# Concatenative language

**Source:** https://concatenative.org/wiki/view/Concatenative%20language

Concatenative language



![](data:image/svg+xml;utf8,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 xmlns:xlink=%27http://www.w3.org/1999/xlink%27 width=%2724%27 height=%2716%27 viewBox=%270 0 120 100%27 fill=%27rgb(0,0,0)%27%3E%3Crect y=%270%27 width=%27120%27 height=%2720%27 rx=%2710%27 /%3E%3Crect y=%2740%27 width=%27120%27 height=%2720%27 rx=%2710%27 /%3E%3Crect y=%2780%27 width=%27120%27 height=%2720%27 rx=%2710%27 /%3E%3C/svg%3E)
[Front Page](https://concatenative.org/wiki/)
[All Articles](https://concatenative.org/wiki/articles)
[Recent Changes](https://concatenative.org/wiki/changes)
[Random Article](https://concatenative.org/wiki/random)

## [Contents](https://concatenative.org/wiki/view/Contents)

[Concatenative language](https://concatenative.org/wiki/view/Concatenative%20language)

* [ACL](https://concatenative.org/wiki/view/ACL)
* [Ait](https://concatenative.org/wiki/view/Ait)
* [Aocla](https://concatenative.org/wiki/view/Aocla)
* [Breeze](https://concatenative.org/wiki/view/Breeze)
* [Callisto](https://concatenative.org/wiki/view/Callisto)
* [Cat](https://concatenative.org/wiki/view/Cat)
* [Cognate](https://concatenative.org/wiki/view/Cognate)
* [colorForth](https://concatenative.org/wiki/view/colorForth)
* [Concata](https://concatenative.org/wiki/view/Concata)
* [CoSy](https://concatenative.org/wiki/view/CoSy)
* [Deque](https://concatenative.org/wiki/view/Deque)
* [DSSP](https://concatenative.org/wiki/view/DSSP)
* [dt](https://concatenative.org/wiki/view/dt)
* [Elymas](https://concatenative.org/wiki/view/Elymas)
* [Enchilada](https://concatenative.org/wiki/view/Enchilada)
* [ERIShell](https://concatenative.org/wiki/view/ERIShell)
* [ETAC](https://concatenative.org/wiki/view/ETAC)
* [F](https://concatenative.org/wiki/view/F)
* [Factor](https://concatenative.org/wiki/view/Factor)
* [Fiveth](https://concatenative.org/wiki/view/Fiveth)
* [Forth](https://concatenative.org/wiki/view/Forth)
* [Fourth](https://concatenative.org/wiki/view/Fourth)
* [Freelang](https://concatenative.org/wiki/view/Freelang)
* [Gershwin](https://concatenative.org/wiki/view/Gershwin)
* [hex](https://concatenative.org/wiki/view/hex)
* [iNet](https://concatenative.org/wiki/view/iNet)
* [Joy](https://concatenative.org/wiki/view/Joy)
* [Joy of Postfix](https://concatenative.org/wiki/view/Joy%20of%20Postfix) *App*
* [kcats](https://concatenative.org/wiki/view/kcats)
* [Kitten](https://concatenative.org/wiki/view/Kitten)
* [lang5](https://concatenative.org/wiki/view/lang5)
* [Listack](https://concatenative.org/wiki/view/Listack)
* [LSE64](https://concatenative.org/wiki/view/LSE64)
* [Lviv](https://concatenative.org/wiki/view/Lviv)
* [Meow5](https://concatenative.org/wiki/view/Meow5)
* [min](https://concatenative.org/wiki/view/min)
* [Mirth](https://concatenative.org/wiki/view/Mirth)
* [mjoy](https://concatenative.org/wiki/view/mjoy)
* [Mlatu](https://concatenative.org/wiki/view/Mlatu)
* [Ode](https://concatenative.org/wiki/view/Ode)
* [OForth](https://concatenative.org/wiki/view/OForth)
* [Om](https://concatenative.org/wiki/view/Om)
* [Onion](https://concatenative.org/wiki/view/Onion)
* [Onyx](https://concatenative.org/wiki/view/Onyx)
* [Plorth](https://concatenative.org/wiki/view/Plorth)
* [Popr](https://concatenative.org/wiki/view/Popr)
* [Porth](https://concatenative.org/wiki/view/Porth)
* [PostScript](https://concatenative.org/wiki/view/PostScript)
* [Prowl](https://concatenative.org/wiki/view/Prowl)
* [Quackery](https://concatenative.org/wiki/view/Quackery)
* [Quadrate](https://concatenative.org/wiki/view/Quadrate)
* [Quest32](https://concatenative.org/wiki/view/Quest32)
* [r3](https://concatenative.org/wiki/view/r3)
* [Raven](https://concatenative.org/wiki/view/Raven)
* [Retro](https://concatenative.org/wiki/view/Retro)
* [RPL](https://concatenative.org/wiki/view/RPL)
* [SPL](https://concatenative.org/wiki/view/SPL)
* [Staapl](https://concatenative.org/wiki/view/Staapl)
* [Stabel](https://concatenative.org/wiki/view/Stabel)
* [Tal](https://concatenative.org/wiki/view/Tal)
* [Titan](https://concatenative.org/wiki/view/Titan)
* [Trith](https://concatenative.org/wiki/view/Trith)
* [Uiua](https://concatenative.org/wiki/view/Uiua)
* [Worst](https://concatenative.org/wiki/view/Worst)
* [xs](https://concatenative.org/wiki/view/xs)
* [XY](https://concatenative.org/wiki/view/XY)
* [5th](https://concatenative.org/wiki/view/5th)
* [8th](https://concatenative.org/wiki/view/8th)

Concatenative topics

* [Compilers](https://concatenative.org/wiki/view/Compilers)
* [Interpreters](https://concatenative.org/wiki/view/Interpreters)
* [Type systems](https://concatenative.org/wiki/view/Type%20systems)
* [Object systems](https://concatenative.org/wiki/view/Object%20systems)
* [Quotations](https://concatenative.org/wiki/view/Quotations)
* [Variables](https://concatenative.org/wiki/view/Variables)
* [Garbage collection](https://concatenative.org/wiki/view/Garbage%20collection)
* [Example programs](https://concatenative.org/wiki/view/Example%20programs)

Concatenative meta

* [People](https://concatenative.org/wiki/view/People)
* [Communities](https://concatenative.org/wiki/view/Communities)
* [Events](https://concatenative.org/wiki/view/Events)

Other languages

* [APL](https://concatenative.org/wiki/view/APL)
* [C++](https://concatenative.org/wiki/view/C%2B%2B)
* [Erlang](https://concatenative.org/wiki/view/Erlang)
* [FP trivia](https://concatenative.org/wiki/view/FP%20trivia)
* [Haskell](https://concatenative.org/wiki/view/Haskell)
* [Io](https://concatenative.org/wiki/view/Io)
* [Java](https://concatenative.org/wiki/view/Java)
* [JavaScript](https://concatenative.org/wiki/view/JavaScript)
* [Lisp](https://concatenative.org/wiki/view/Lisp)
* [ML](https://concatenative.org/wiki/view/ML)
* [Oberon](https://concatenative.org/wiki/view/Oberon)
* [RPL](https://concatenative.org/wiki/view/RPL)
* [Self](https://concatenative.org/wiki/view/Self)
* [Slate](https://concatenative.org/wiki/view/Slate)
* [Smalltalk](https://concatenative.org/wiki/view/Smalltalk)

Meta

* [**Search**](http://www.google.com/custom?hl=en&cof=&domains=concatenative.org&btnG=Search&sitesearch=concatenative.org)
* [Farkup wiki format](https://concatenative.org/wiki/view/Farkup)
* [Etiquette](https://concatenative.org/wiki/view/Etiquette)
* [Sandbox](https://concatenative.org/wiki/view/Sandbox)

# Concatenative language

There are many ways to categorize programming languages; one is to define them as either "concatenative" or "applicative". In an applicative language, things are evaluated by applying functions to arguments. This includes almost all programming languages in wide use, such as [C](https://concatenative.org/wiki/view/C), [Python](https://concatenative.org/wiki/view/Python), [ML](https://concatenative.org/wiki/view/ML), [Haskell](https://concatenative.org/wiki/view/Haskell), and [Java](https://concatenative.org/wiki/view/Java). In a concatenative programming language, things are evaluated by composing several functions which all operate on a single piece of data, passed from function to function. This piece of data is usually in the form of a stack. Additionally, in concatenative languages, this function composition is indicated by concatenating programs. Examples of concatenative languages include [Forth](https://concatenative.org/wiki/view/Forth), [Joy](https://concatenative.org/wiki/view/Joy), [PostScript](https://concatenative.org/wiki/view/PostScript), [Cat](https://concatenative.org/wiki/view/Cat), and [Factor](https://concatenative.org/wiki/view/Factor).

# Concatenative and stack languages

Although the terms *stack language* and *concatenative language* sometimes get thrown around interchangeably, they actually represent similar but distinct classes of languages. A concatenative language is not necessarily a stack language. For example, [Om](https://concatenative.org/wiki/view/Om) uses prefix notation, rather than postfix, and passes the remainder of the program as the data from function to function. See [Deque](https://concatenative.org/wiki/view/Deque) for another example of a stack-free concatenative language.

Stacks are a pretty fundamental concept in computer science, and many languages use stacks internally in the implementation. Any language that allows recursive definitions uses some type of call stack to save return addresses between function calls, and often the same stack is used to spill values which cannot be allocated in registers. However, this is just implementation detail, and this call stack is not exposed directly to the programmer (except in languages with first-class continuations; I'll touch upon this later).

So what makes stack languages different? The key concept here is that there are *multiple* stacks: all stack languages have a call stack to support recursion, but they also have a data stack (sometimes called an operand stack) to pass values between functions. The latter is what stack language programmers mean when they talk about "the" stack.

Most languages in widespread use today are *applicative languages*: the central construct in the language is some form of function call, where a function is *applied* to a set of parameters, where each parameter is itself the result of a function call, the name of a variable, or a constant. In stack languages, a function call is made by simply writing the name of the function; the parameters are implicit, and they have to *already* be on the stack when the call is made. The result of the function call (if any) is then left on the stack after the function returns, for the next function to consume, and so on. Because functions are invoked simply by mentioning their name without any additional syntax, Forth and Factor refer to functions as "words", because in the syntax they really are just words.

# One mutable stack or functions from stacks to stacks?

Sometimes, people talk about words pushing and popping values on "the stack". Other programmers, mostly those who prefer the term "concatenative language", instead talk about words as being functions which take a stack as input, and return a whole new stack as output. The first point of view is more intuitive, and it is also how most implementations work: there really is a location in memory that is the data stack. The latter is more amenable to formal reasoning: it is easier to work with rewrite rules and type systems if your functions are pure. However, these two points of view are equivalent: because in a given thread of execution, only one stack is "live" at any given point in time, updating the stack in-place has the same semantics as the purely functional world view. More details about this can be found in [Manfred von Thun](https://concatenative.org/wiki/view/Manfred%20von%20Thun)'s paper [Mathematical Foundations of Joy](https://hypercubed.github.io/joy/html/j02maf.html).

# Fundamentals of concatenative languages

* [Name code not values](https://concatenative.org/wiki/view/Concatenative%20language/Name%20code%20not%20values)
* [Multiple return values](https://concatenative.org/wiki/view/Concatenative%20language/Multiple%20return%20values)
* [Concatenation is composition](https://concatenative.org/wiki/view/Concatenative%20language/Concatenation%20is%20composition)
* [Left to right evaluation](https://concatenative.org/wiki/view/Concatenative%20language/Left%20to%20right%20evaluation)

# Concatenative idioms

* [Keyword parameters](https://concatenative.org/wiki/view/Concatenative%20language/Keyword%20parameters)
* [Rest parameters](https://concatenative.org/wiki/view/Concatenative%20language/Rest%20parameters)
* [Pipeline style](https://concatenative.org/wiki/view/Pipeline%20style)

# Other interesting properties

* [Concision](https://concatenative.org/wiki/view/Concatenative%20language/Concision)
* [Simplicity](https://concatenative.org/wiki/view/Concatenative%20language/Simplicity)
* [Meta-programming](https://concatenative.org/wiki/view/Concatenative%20language/Meta-programming)
* [Continuations](https://concatenative.org/wiki/view/Concatenative%20language/Continuations)
* [Interactive development](https://concatenative.org/wiki/view/Concatenative%20language/Interactive%20development)

# Publications

* [Publications](https://concatenative.org/wiki/view/Concatenative%20language/Publications)

*This revision created on Fri, 10 Sep 2021 18:36:34 by [AliAsshole](https://concatenative.org/wiki/user-edits/AliAsshole)
(Replaced dead link with live one)*

[Latest](https://concatenative.org/wiki/view/Concatenative%20language)
[Revisions](https://concatenative.org/wiki/revisions/Concatenative%20language)
[Edit](https://concatenative.org/wiki/edit/Concatenative%20language)


Delete



All content is © 2008-2024 by its respective authors. By adding content to this wiki, you agree to release it under the [BSD license](https://factorcode.org/license.txt).