Concatenative programming language
A concatenative programming language is a point-free computer programming language in which all expressions denote functions, and the juxtaposition of expressions denotes function composition.<ref name="dobbscodetalk">Template:Cite magazine</ref> Concatenative programming replaces function application, which is common in other programming paradigms, with function composition as the default way to build subroutines.
Example
For example, a nesting of operations in an applicative language like the following:
<syntaxhighlight lang="javascript"> baz(bar(foo(x))) </syntaxhighlight>
...is written in a concatenative language as a sequence of functions:<ref>Template:Cite web</ref>
x foo bar baz
Functions and procedures written in concatenative style are not value level, i.e., they typically do not represent the data structures they operate on with explicit names or identifiers. Instead they are function level – a function is defined as a pipeline, or a sequence of operations that take parameters from an implicit data structure on which all functions operate, and return the function results to that shared structure so that it will be used by the next operator.<ref>Template:Cite web</ref>
The combination of compositional semantics with a syntax that mirrors such a semantic makes concatenative languages highly amenable to algebraic manipulation of programs;<ref>Template:Cite web</ref> although it may be difficult to write mathematical expressions directly in them.<ref name="whymatters"/> Concatenative languages can be implemented efficiently with a stack machine, and are commonly present implicitly in virtual machines in the form of their instruction sets.<ref name="whymatters">Template:Cite web</ref>
Properties
The properties of concatenative languages are the result of their compositional syntax and semantics:
- The reduction of any expression is the simplification of one function to another function; it is never necessary to deal with the application of functions to objects.<ref>Template:Cite web</ref>
- Any subexpression can be replaced with a name that represents the same subexpression. In concatenative programming practice, this is called factoring, and is used extensively to simplify programs into smaller parts.
- The syntax and semantics of concatenative languages form the algebraic structure of a monoid.<ref>Template:Cite web</ref>
- Concatenative languages can be made well-suited to an implementation inspired by linear logic where no garbage is ever generated.<ref>Template:Cite report</ref>
Implementations
The first concatenative programming language was Forth, although Joy was the first language which was termed concatenative. Other concatenative languages are dc, Factor, Onyx, PostScript, RPL, Staapl,<ref name="Staapl">Template:Cite web</ref> and experimental and discontinued ones including: Enchilada,<ref name="Enchilada">Template:Cite web</ref> Om,<ref name="Om">Template:Cite web</ref> XY.<ref name="XY">Template:Cite web</ref>
Most existing concatenative languages are stack-based. This is not required, and other models have been proposed.<ref name="XY"/><ref name="Enchilada"/><ref name="Om"/> Concatenative languages are currently used for embedded,<ref name="Staapl"/> desktop, and web programming, as target languages, and for research purposes.
Most concatenative languages are dynamically typed. Exceptions include the statically typed Cat language<ref>Template:Cite web</ref> and its successor, Kitten.<ref>Template:Cite web</ref>
See also
References
External links
- Concatenative.org: Wiki, about concatenative programming
Template:Programming paradigms navbox Template:Types of programming languages