Circular Programs and Self-Referential Structures

Lloyd Allison
DOI: https://doi.org/10.1002/spe.4380190202
2024-03-04
Abstract: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.
Programming Languages
What problem does this paper attempt to address?
The problem this paper attempts to address is how to implement classic data structures such as loops, doubly linked lists, threaded trees, and queues in functional programming languages, which are typically thought to require updatable variables in imperative languages. Additionally, the paper explores how to improve space efficiency by avoiding the creation of intermediate temporary data structures and demonstrates how to apply loop programming techniques to imperative languages to achieve elegant and efficient programs. Specifically, the main contributions of the paper include: 1. **Extending the application scope of loop programs**: The paper demonstrates the broad application of loop programs as a programming technique, not limited to specific program transformation scenarios but also applicable to the implementation of various classic data structures. 2. **Improving space efficiency**: By avoiding the creation of temporary data structures that require subsequent garbage collection, loop programs can be more space-efficient than traditional programs. 3. **Applicable to imperative languages**: Even in imperative languages, loop programs can be achieved through some simple transformations, resulting in elegant and efficient code. The paper illustrates the application and advantages of these techniques through multiple specific examples (such as circular lists, doubly linked lists, threaded trees, breadth-first traversal, deduplication functions, and prime number sieves).