# Concatenative programming language

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Concatenative_programming_language
> Markdown URL: https://mediated.wiki/source/Concatenative_programming_language.md
> Source: https://en.wikipedia.org/wiki/Concatenative_programming_language
> Source revision: 1347399448
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

{{Short description|Type of programming language}}

A '''concatenative programming language''' is a [point-free](/source/Point-free_programming) computer [programming language](/source/programming_language) in which all expressions denote [functions](/source/Function_(mathematics)), and the [juxtaposition](/source/juxtaposition) of [expressions](/source/Expression_(computer_science)) denotes [function composition](/source/function_composition).<ref name="dobbscodetalk">{{cite magazine |last1=Diggins |first1=Christopher |date=2008-12-31 |url=http://drdobbs.com/blogs/architecture-and-design/228701299 |title=What is a concatenative language |magazine=[Dr. Dobb's Journal](/source/Dr._Dobb's_Journal) |access-date=2013-07-01}}</ref> Concatenative programming replaces [function application](/source/function_application), which is common in other [programming paradigm](/source/programming_paradigm)s, with [function composition](/source/Function_composition_(computer_science)) as the default way to build [subroutines](/source/Function_(computer_programming)).

==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>{{cite web |url=http://concatenative.org/wiki/view/Concatenative%20language/Name%20code%20not%20values |title=Name code not values |publisher=Concatenative.org |access-date=13 September 2013}}</ref>

 x foo bar baz

Functions and procedures written in concatenative style are not [value level](/source/Value-level_programming), i.e., they typically do not represent the data structures they operate on with explicit names or [identifiers](/source/Identifier). Instead they are [function level](/source/Function-level_programming) – a function is defined as a [pipeline](/source/pipeline_(software)), or a sequence of operations that take parameters from an implicit [data structure](/source/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>{{cite web |url=http://concatenative.org/wiki/view/Concatenative%20language |title=Concatenative language |publisher=Concatenative.org |access-date=13 September 2013|archive-url=https://web.archive.org/web/20241008135442/https://concatenative.org/wiki/view/Concatenative%20language|archive-date=8 October 2024|url-status=dead|website=Concatenative.org|date=13 September 2013}}</ref>

The combination of compositional [semantics](/source/Semantics_(computer_science)) with a [syntax](/source/Syntax_(programming_languages)) that mirrors such a semantic makes concatenative languages highly amenable to algebraic manipulation of programs;<ref>{{cite web |url=http://www.latrobe.edu.au/philosophy/phimvt/joy/j00rat.html |archive-url=https://web.archive.org/web/20110115151536/http://www.latrobe.edu.au/philosophy/phimvt/joy/j00rat.html |archive-date=2011-01-15 |title=Rationale for Joy, a functional language}}</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](/source/stack_machine), and are commonly present implicitly in [virtual machine](/source/virtual_machine)s in the form of their [instruction set](/source/instruction_set)s.<ref name="whymatters">{{cite web |last1=Purdy |first1=Jon |date=12 February 2012 |url=http://evincarofautumn.blogspot.com/2012/02/why-concatenative-programming-matters.html |title=Why Concatenative Programming Matters |website=The Big Mud Puddle |access-date=12 August 2025}}</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>{{cite web |last1=von Thun |first1=Manfred |year=2011 |url=http://www.latrobe.edu.au/phimvt/joy/j08cnt.html |title=Joy compared with other functional languages |archive-url=https://web.archive.org/web/20111006225512/http://www.latrobe.edu.au/phimvt/joy/j08cnt.html |archive-date=2011-10-06}}</ref>
* Any subexpression can be replaced with a name that represents the same subexpression. In concatenative programming practice, this is called [factoring](/source/Code_refactoring), and is used extensively to simplify programs into smaller parts.
* The syntax and semantics of concatenative languages form the algebraic structure of a [monoid](/source/monoid).<ref>{{cite web |last1=von Thun |first1=Manfred |year=2009 |url=http://www.latrobe.edu.au/philosophy/phimvt/joy/j02maf.html |title=Mathematical foundations of Joy |archive-url=https://web.archive.org/web/20100731060810/http://www.latrobe.edu.au/philosophy/phimvt/joy/j02maf.html |archive-date=2010-07-31}}</ref>
* Concatenative languages can be made well-suited to an implementation inspired by [linear logic](/source/linear_logic) where no [garbage](/source/Garbage_(computer_science)) is ever generated.<ref>{{cite report |last1=Baker |first1=Henry |year=1993 |url=http://home.pipeline.com/~hbaker1/ForthStack.html |title=Linear Logic and Permutation Stacks: The Forth Shall Be First |publisher=Nimble Computer Corporation |via=Home.pipeline.com |access-date=2013-07-01 |archive-url=https://web.archive.org/web/20140724091729/http://home.pipeline.com/~hbaker1/ForthStack.html |archive-date=2014-07-24 |url-status=dead}}</ref>

==Implementations==
The first concatenative programming language was [Forth](/source/Forth_(programming_language)), although [Joy](/source/Joy_(programming_language)) was the first language which was termed concatenative. Other concatenative languages are [dc](/source/dc_(computer_program)), [Factor](/source/Factor_(programming_language)), Onyx, [PostScript](/source/PostScript), [RPL](/source/RPL_(programming_language)), Staapl,<ref name="Staapl">{{cite web |last1=Schouten |first1=Tom (zwizwa) |date=<!-- Undated --> |url=http://zwizwa.be/staapl/ |title=Staapl: Forth on Scheme for Embedded Controllers |website=Zwizwa LLC |access-date=12 August 2025}}</ref> and experimental and discontinued ones including:<!-- Alphabetic order--> Enchilada,<ref name="Enchilada">{{cite web |author1=rapido |author2=NewDave |author3=jacintheford |author4=goren |date=2 January 2024 |url=https://concatenative.org/wiki/view/Enchilada |title=Enchilada |website=Concatenative.org |access-date=12 August 2025}}</ref> Om,<ref name="Om">{{cite web |author1=sparist |date=<!-- Undated --> |url=https://www.om-language.com/ |title=The Om Programming Language |website=Om-language.com |access-date=12 August 2025}}</ref> XY.<ref name="XY">{{cite web |last1=Apter |first1=Stevan |date=2004 |url=http://www.nsl.com/k/xy/xy.htm |title=The Concatenative Language XY |website=no stinking loops |access-date=12 August 2025}}</ref>

Most existing concatenative languages are [stack-based](/source/Stack-oriented_programming). 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](/source/Embedded_system),<ref name="Staapl"/> [desktop](/source/Application_software), and [web programming](/source/Web_development), as [target languages](/source/Translator_(computing)), and for research purposes.

Most concatenative languages are [dynamically typed](/source/dynamically_typed). Exceptions include the [statically typed](/source/statically_typed) Cat language<ref>{{cite web|url=http://www.cat-language.com/manual.html |title=Cat Specification |publisher=Cat-language.com |access-date=2013-07-01 |archive-url=https://web.archive.org/web/20150205081218/http://cat-language.com/manual.html |archive-date=2015-02-05}}</ref> and its successor, Kitten.<ref>{{Cite web |last1=Purdy |first1=Jon |title=Kitten Programming Language |url=https://kittenlang.org/ |access-date=2025-03-31 |website=kittenlang.org}}{{Dead link|date=February 2026}}</ref>

==See also==
* [Function-level programming](/source/Function-level_programming)
* [Homoiconicity](/source/Homoiconicity)
* [Stack-oriented programming language](/source/Stack-oriented_programming_language)
* [Tacit programming](/source/Tacit_programming)

==References==
{{Reflist}}

==External links==
* [http://www.concatenative.org/ Concatenative.org: Wiki], about concatenative programming

{{Programming paradigms navbox}}
{{Types of programming languages}}

{{DEFAULTSORT:Concatenative Programming Language}}
Category:Concatenative programming languages
<!-- Hidden categories below -->
Category:Articles with example JavaScript code

---
Adapted from the Wikipedia article [Concatenative programming language](https://en.wikipedia.org/wiki/Concatenative_programming_language) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Concatenative_programming_language?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
