Concatenative programming language
In computer science, a concatenative programming language is one in which functions are composed by juxtaposition (writing them in sequence separated by whitespace). For example, given two functions and , is a function where is applied to the function's input, and then is applied to that result (this is function composition, written in mathematics). Note that the order of composition in a concatenative language is left-to-right, so that data flows in the same direction as a left-to-right writing system, in contrast with the right-to-left notation used in mathematics. This style of programming is point-free, as it does not explicitly refer to the input data.
For example, a sequence of operations in an applicative language like the following:
y = foo(x) z = bar(y) w = baz(z)
...is written in a concatenative language as a sequence of functions, without parameters:
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, 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.
The combination of a compositional semantics with a syntax that mirrors such a semantics makes concatenative languages highly amenable to algebraic manipulation of programs; although it may be difficult to write mathematical expressions directly in them. Concatenative languages can be implemented in an efficient way with a stack machine, and are commonly present implicitly in virtual machines in the form of their instruction sets.
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.
- Any subexpression can be replaced with a name that represents the same subexpression. This is referred to in the concatenative community as 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.
- Concatenative languages can be made well-suited to an implementation inspired by linear logic where no garbage is ever generated.
Most existing concatenative languages are stack-based; this is not a requirement and other models have been proposed. Concatenative languages are currently used for embedded, desktop, and web programming, as target languages, and for research purposes.
- "Name code not values". Concatenative.org. Retrieved 13 September 2013.
- "Concatenative language". Concatenative.org. Retrieved 13 September 2013.
- "Rationale for Joy, a functional language". Archived from the original on 2011-01-15.
- "Why Concatenative Programming Matters". Retrieved 13 September 2013.
- "von Thun, Manfred: Joy compared with other functional languages". Archived from the original on 2011-10-06.
- "von Thun, Manfred: Mathematical foundations of Joy". Archived from the original on 2010-07-31.
- "Henry Baker: Linear Logic and Permutation Stacks — The Forth Shall Be First". Home.pipeline.com. Retrieved 2013-07-01.
- "The Concatenative Language XY". Nsl.com. Retrieved 2013-07-01.
- "The Enchilada Programming Language". Enchiladacode.nl. Retrieved 2013-07-01.
- "The Om Programming Language". Om-language.org. Retrieved 2013-07-01.
- "Cat Specification". Cat-language.com. Archived from the original on 2015-02-05. Retrieved 2013-07-01.