Unlambda

Paradigm | Nearly pure functional |
---|---|

Designed by | David Madore |

Developer | David Madore |

First appeared | 28 June 1999 |

Stable release |
2.0.0
/ 20 December 1999 |

Typing discipline | Untyped |

Implementation language | Scheme, C, Java |

License | GPL 2.0 or later |

Website |
www |

**Unlambda** is a minimal, "nearly pure"^{[1]}functional programming language invented by David Madore. It is based on combinatory logic, a version of the lambda calculus that omits the lambda operator. It relies mainly on two built-in functions (`s`

and `k`

) and an apply operator (written ```

, the backquote character). These alone make it Turing-complete, but there are also some input/output (I/O) functions to enable interacting with the user, some shortcut functions, and a lazy evaluation function. Variables are unsupported.

Unlambda is free and open-source software distributed under a GNU General Public License (GPL) 2.0 or later.

As an esoteric programming language, Unlambda is meant as a demonstration of very pure functional programming rather than for practical use. Its main feature is the lack of conventional operators and data types—the only kind of data in the program are one-parameter functions. Data can nevertheless be simulated with appropriate functions as in the lambda calculus. Multi-parameter functions can be represented via the method of currying.

Unlambda is based on the principle of abstraction elimination, or the elimination of all saved variables, including functions. As a purely functional language, Unlambda's functions are first-class objects, and are the *only* such objects.

Here is an implementation of a hello world program in Unlambda:^{[1]}

`r```````````.H.e.l.l.o. .w.o.r.l.di

The notation `.`

denotes a function which takes one argument and returns it unchanged, printing the single character *x**x* as a side effect when it is invoked. `i`

represents the version of the identity function that has no such side effect; it is used here as a dummy argument. The program ``.di`

applies the `d`

-printing function to a dummy argument of `i`

, returning `i`

and printing the letter `d`

as a side effect. Similarly, ```.l.di`

first applies `.l`

to `.d`

, printing the letter `l`

and returning `.d`

; this result of `.d`

is then applied to `i`

as in the previous example. The function `r`

is syntactic sugar for the function that prints a newline character.

Other important features provided by Unlambda include the `k`

and `s`

functions. `k`

manufactures constant functions: the result of ``k`

is a function which, when invoked, returns *x**x*. Thus the value of ```k`

is *xy**x* for any *x* and *y*.

`s`

is a generalized evaluation operator. ````s`

evaluates to *xyz*````

for any *xz*`*yz**x*, *y*, and *z*. It is a remarkable fact that `s`

and `k`

are sufficient to perform any calculation, as described in SKI combinator calculus. As a brief example, the identity function `i`

can be implemented as ```skk`

, since ````skk`

yields *x**x* for all *x*.

Unlambda's one flow control construct is call with current continuation, denoted `c`

. When an expression of the form ``c`

is evaluated, a special *x**continuation* object is constructed, representing the state of the interpreter at that moment. Then *x* is evaluated, and then the result is given the continuation object as an argument. If the continuation is never applied to an argument, the value of the ``c`

expression is the same as the value of *x**x*. But if the continuation object is applied to a value *y*, execution of *x* is immediately aborted, and the value of the entire ``c`

expression is *x**y*.

Unlambda's execution semantics are normally eager evaluation, but a lazy evaluation option exists, indicated by the use of the `d`

operator. Usually, to evaluate an expression of the form ```

, unlambda first evaluates *xy**x*, then *y*, and then applies *x* to *y*. However, if *x* evaluates to the special value `d`

, then *y* is *not* evaluated; instead, the value of the expression ``d`

is a special "delayed computation" object, which, when applied to an argument *y**z*, evaluates *y*, and then applies its value to *z*. In the absence of side effects, this is exactly the same as ``i`

. The difference is that *y*``i`

executes any side effects in *y**y* immediately, whereas ``d`

defers the side effects until the result is applied to another argument.
*y*

Unlambda's next built-in operator is `v`

, which ignores its argument and returns `v`

. This feature is not strictly necessary, since `v`

could be implemented as ```s`k``s``s`kskk`k``s``s`kskk`

, but it is supplied as a convenience. (This expression above is simply ``Yk`

, where `Y`

denotes a fixed point combinator.)

More built-ins were introduced in Unlambda version 2. Input is facilitated by operators `@`

and `?`

. When *u*`@`

is applied to a function *x*, a character is read from input, and stored as the "current character"; then *x* is applied to `i`

. However, if no more characters were available on input, the *current character* is left undefined, and *x* is applied to `v`

instead. When a function `?`

is applied to a function *u**x*, the result is the evaluation of ```

if the current character is *x*i*u*, otherwise ```

is evaluated.
*x*v

There is also a "reprint" operator `|`

. When ``|`

is evaluated, the function *x**x* is applied to `.`

if *u**u* is the current character, or to `v`

if there is no current character.

Finally, there is an exit operator `e`

. When `e`

is applied to *x*, the execution of the program is terminated, and *x* is taken as the result of the program (most of the currently existing interpreters ignore the result anyway).

- ^
^{a}^{b}Chu-Carroll, Mark C. (2006-08-11). "Friday Pathological Programming: Unlambda, or Programming Without Variables".*Good Math, Bad Math*(blog)*. ScienceBlogs.*

- Felix-Hernandez Campos (1 April 2002),
*Lecture 28: More on functional programming*, University of North Carolina COMP144 - ? ? (Yutaka Hara) (2008).
*Ruby*(in Japanese). T?ky?: Mainichikomyunik?shonzu. pp. 205-214. ISBN 4-8399-2784-7.

This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.

What We've Done

Led Digital Marketing Efforts of Top 500 e-Retailers.

Worked with Top Brands at Leading Agencies.

Successfully Managed Over $50 million in Digital Ad Spend.

Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.

Taught Advanced Internet Marketing Strategies at the graduate level.

Manage research, learning and skills at defaultlogic.com. Create an account using LinkedIn to manage and organize your omni-channel knowledge. defaultlogic.com is like a shopping cart for information -- helping you to save, discuss and share.