Multistack Concatenative Programming Languages
Concatenative programming languages, or catlangs, focus on composing programs through point-free composition. The core concept is "juxtaposition is composition," emphasizing the use of a data stack and an implicit call stack for holding terms and execution tokens. Quotations, which are lists of terms that can be manipulated as data and possibly executed as code, are a key feature of catlangs. The convention of using [ ] for quotations, popularized by Joy, has largely remained unexplored in terms of ergonomics.
Managing the data stack can be challenging, as poorly structured dataflow can lead to messy code that is write-only. Some catlangs provide an auxiliary stack to temporarily dip under values, but the desire to name values instead of names code remains. Adding lexical variables can ease the burden of managing the data stack, but these only provide short-term benefits and do not compose via concatenation.
Logic with lexical variables cannot be decomposed without extracting or propagating them manually, often resulting in C-like code that feels awkward and backwards.
Non-lexical bindings, available in languages like Factor and PostScript, offer an escape hatch without compromising concatenation. These enable dynamically shifting the current context for values and words. Some high-level catlangs are exploring a system of multiple named stacks that propagate alongside the data stack. These stacks can be summoned as needed, and values can be pushed, peeked, and popped from them, allowing them to model nested scopes.
Mirth adds a convenience operation around named stacks to emulate lexical binding, but with stack effect checking, type-checking, and static analysis, invariant behavior can be strictly enforced, preventing values from leaking or being accidentally destroyed.
Named stacks could also help eliminate the need for constructing closure objects, as an anonymous function can access the current environment instead of creating objects. Object-oriented catlangs like StackTalk and Kit explore applying named stacks to objects, which are collections of named stacks used for word and value lookup.
The full potential of named stacks is still being explored, with various projects, such as Endless and Joyful, experimenting with dedicated lexical variable stacks to resolve conflicts between lexical bindings and quotations.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — it may contain errors, so check the original before relying on it.