循环程序与自引用结构
Circular Programs and Self-Referential Structures
AI总结:
本文介绍利用循环程序和自引用结构在函数式语言中实现循环链表、双向链表、线索树和队列,并通过避免中间临时结构提升空间效率。
摘要:
循环程序会创建这样一种数据结构:其计算依赖于自身,或引用自身。该技术用于在函数式编程语言中实现经典数据结构,包括循环链表、双向链表、线索树和队列。通常人们认为这些结构需要命令式语言中的可更新变量才能实现。文中给出了一个对树执行广度优先遍历的函数式程序示例。部分示例在求值时会产生循环数据结构。还有一些示例通过避免创建原本稍后会成为垃圾的中间临时结构,实现了特别高的空间效率。最后,该技术也可应用于命令式语言,从而得到优雅的程序。
英文摘要:
A circular program creates a data structure whose computation depends upon itself or refers to itself. The technique is used to implement the classic data structures circular and doubly-linked lists, threaded trees and queues, in a functional programming language. These structures are normally thought to require updatable variables found in imperative languages. For example, a functional program to perform the breadth-first traversal of a tree is given. Some of the examples result in circular data structures when evaluated. Some examples are particularly space-efficient by avoiding the creation of intermediate temporary structures which would otherwise later become garbage. Lastly, the technique can be applied in an imperative language to give an elegant program.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。