A concatenative programming language is a
point-free computer
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
in which all expressions denote
functions, and the
juxtaposition
Juxtaposition is an act or instance of placing two opposing elements close together or side by side. This is often done in order to Comparison, compare/contrast the two, to show similarities or differences, etc.
Speech
Juxtaposition in literary ...
of
expressions denotes
function composition
In mathematics, the composition operator \circ takes two function (mathematics), functions, f and g, and returns a new function h(x) := (g \circ f) (x) = g(f(x)). Thus, the function is function application, applied after applying to . (g \c ...
.
Concatenative programming replaces
function application
In mathematics, function application is the act of applying a function to an argument from its domain so as to obtain the corresponding value from its range. In this sense, function application can be thought of as the opposite of function abs ...
, which is common in other programming styles, with
function composition
In mathematics, the composition operator \circ takes two function (mathematics), functions, f and g, and returns a new function h(x) := (g \circ f) (x) = g(f(x)). Thus, the function is function application, applied after applying to . (g \c ...
as the default way to build
subroutine
In computer programming, a function (also procedure, method, subroutine, routine, or subprogram) is a callable unit of software logic that has a well-defined interface and behavior and can be invoked multiple times.
Callable units provide a ...
s.
Example
For example, a nesting of operations in an applicative language like the following:
baz(bar(foo(x)))
...is written in a concatenative language as a sequence of functions:
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
An identifier is a name that identifies (that is, labels the identity of) either a unique object or a unique ''class'' of objects, where the "object" or class may be an idea, person, physical countable object (or class thereof), or physical mass ...
. Instead they are
function levela function is defined as a
pipeline
A pipeline is a system of Pipe (fluid conveyance), pipes for long-distance transportation of a liquid or gas, typically to a market area for consumption. The latest data from 2014 gives a total of slightly less than of pipeline in 120 countries ...
, or a sequence of operations that take parameters from an implicit
data structure
In computer science, a data structure is a data organization and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the relationships amo ...
upon 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 compositional
semantics
Semantics is the study of linguistic Meaning (philosophy), meaning. It examines what meaning is, how words get their meaning, and how the meaning of a complex expression depends on its parts. Part of this process involves the distinction betwee ...
with a
syntax
In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
that mirrors such a semantic 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 efficiently with a
stack machine
In computer science, computer engineering and programming language implementations, a stack machine is a computer processor or a Virtual machine#Process virtual machines, process virtual machine in which the primary interaction is moving short- ...
, and are commonly present implicitly in
virtual machine
In computing, a virtual machine (VM) is the virtualization or emulator, emulation of a computer system. Virtual machines are based on computer architectures and provide the functionality of a physical computer. Their implementations may involve ...
s in the form of their
instruction set
In computer science, an instruction set architecture (ISA) is an abstract model that generally defines how software controls the CPU in a computer or a family of computers. A device or program that executes instructions described by that ISA, s ...
s.
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.
* 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
In abstract algebra, a monoid is a set equipped with an associative binary operation and an identity element. For example, the nonnegative integers with addition form a monoid, the identity element being .
Monoids are semigroups with identity ...
.
* Concatenative languages can be made well-suited to an implementation inspired by
linear logic
Linear logic is a substructural logic proposed by French logician Jean-Yves Girard as a refinement of classical and intuitionistic logic, joining the dualities of the former with many of the constructive properties of the latter. Although the ...
where no
garbage
Garbage, trash (American English), rubbish (British English), or refuse is waste material that is discarded by humans, usually due to a perceived lack of utility. The term generally does not encompass bodily waste products, purely liquid or ...
is ever generated.
Implementations
The first concatenative programming language was
Forth, although
Joy was the first language to call itself concatenative. Other concatenative languages are
dc,
Factor, Onyx,
PostScript
PostScript (PS) is a page description language and dynamically typed, stack-based programming language. It is most commonly used in the electronic publishing and desktop publishing realm, but as a Turing complete programming language, it c ...
, and
RPL.
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
A desktop traditionally refers to:
* The surface of a desk (often to distinguish office appliances that fit on a desk, such as photocopiers and printers, from larger equipment covering its own area on the floor)
Desktop may refer to various compu ...
, and
web programming
Web development is the work involved in developing a website for the Internet (World Wide Web) or an intranet (a private network). Web development can range from developing a simple single static page of plain text to complex web applications, ...
, as
target languages, and for research purposes.
Most concatenative languages are
dynamically typed
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usua ...
. Exceptions include the
statically typed
In computer programming, a type system is a logical system comprising a set of rules that assigns a property called a ''type'' (for example, integer, floating point, string) to every '' term'' (a word, phrase, or other set of symbols). Usu ...
Cat language and its successor, Kitten
.
See also
*
Function-level programming
In computer science, function-level programming refers to one of the two contrasting programming paradigms identified by John Backus in his work on programs as mathematical objects, the other being value-level programming.
In his 1977 Turin ...
*
Homoiconicity
In computer programming, homoiconicity (from the Greek words ''homo-'' meaning "the same" and ''icon'' meaning "representation") is an informal property of some programming languages. A language is homoiconic if a program written in it can be mani ...
*
Stack-oriented programming language
*
Tacit programming
References
External links
concatenative.org: A wiki about concatenative languagesStaapl: Forth on Scheme for Embedded ControllersThe Enchilada Programming LanguageThe Om Programming Language
{{DEFAULTSORT:Concatenative Programming Language