Unlambda

Unlambda is a minimal, "nearly pure" functional programming language invented by David Madore. It is based on combinatory logic, an expression system without the lambda operator or free variables. It relies mainly on two built-in functions ( and  ) 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.

Basic principles
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&mdash;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:

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

Original built-in functions
The notation  denotes a function which takes one argument and returns it unchanged, printing the single character x as a side effect when it is invoked. represents the version of the identity function that has no such side effect; it is used here as a dummy argument. The program  applies the  -printing function to a dummy argument of , returning   and printing the letter   as a side effect. Similarly,  first applies   to , printing the letter   and returning  ; this result of   is then applied to   as in the previous example. The function  is syntactic sugar for the function that prints a newline character.

Other important features provided by Unlambda include the  and   functions. manufactures constant functions: the result of  is a function which, when invoked, returns x. Thus the value of  is x for any x and y.

is a generalized evaluation operator. evaluates to  for any x, y, and z. It is a remarkable fact that  and   are sufficient to perform any calculation, as described in SKI combinator calculus. As a brief example, the identity function  can be implemented as , since   yields x for all x.

Unlambda's one flow control construct is call with current continuation, denoted. When an expression of the form  is evaluated, a special 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  expression is the same as the value of x. But if the continuation object is applied to a value y, execution of x is immediately aborted, and the value of the entire  expression is y.

Unlambda's execution semantics are normally eager evaluation, but a lazy evaluation option exists, indicated by the use of the  operator. Usually, to evaluate an expression of the form, unlambda first evaluates x, then y, and then applies x to y. However, if x evaluates to the special value, then y is not evaluated; instead, the value of the expression   is a special "delayed computation" object, which, when applied to an argument z, evaluates y, and then applies its value to z. In the absence of side effects, this is exactly the same as. The difference is that  executes any side effects in y immediately, whereas   defers the side effects until the result is applied to another argument.

Unlambda's next built-in operator is, which ignores its argument and returns. This feature  is not strictly necessary, since   could be implemented as , but it is supplied as a convenience. (This expression above is simply, where   denotes a fixed point combinator.)

Version 2 built-in functions
More built-ins were introduced in Unlambda version 2. Input is facilitated by operators  and. When  is applied to a function x, a character is read from input, and stored as the "current character"; then x is applied to. However, if no more characters were available on input, the current character is left undefined, and x is applied to  instead. When a function  is applied to a function x, the result is the evaluation of   if the current character is u, otherwise   is evaluated.

There is also a "reprint" operator. When  is evaluated, the function x is applied to   if u is the current character, or to   if there is no current character.

Finally, there is an exit operator. When  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).