Unlambda is aminimal language of functional programming invented by David Madore. It is based on the principle of combinatorial logic , a version of the lambda-calculus that omits the lambda operator. It relies mainly on two built-in functions ( s and k ) and on an apply operator(written ` , the inverted quote). It is therefore a complete Turing languageand also includes some I / O functions allowing user interaction, various shortcut functions and a lazy evaluation function .


Due to its nature of exotic programming language , Unlambda is more a demonstration of functional programming pushed to the extreme than a language usable for practical purposes. Its main feature is its lack of conventional operators and typed variables. The only usable data type consists of single-parameter functions. The user can, however, simulate other data by calling suitable functions, such as lambda-calculus . The functions with several parameters can be represented by the technique of currying .

The Unlambda language is based on the principles of combinatorial logic , in particular as regards the elimination of all variables in memory as well as functions. Since this is a purely functional language, not only are the functions of Unlambda first class objects , but they are also the only ones.

A version of the Hello world in Unlambda can be 1 :

 `R```````````.Hello .worldi

Internal functions

The notation .x​indicates a function taking an argument and returning it unchanged, with the side effect of displaying the character x when called. i​Is a version of the identity function that does not have this side effect. It is therefore used as a fictitious parameter. The code `.di​applies the display to the fictitious d​argument i​, returns i​and displays d​doing so. Similarly, ``.l.di​first applies .l​to .d​, displaying l​and returning .d​, which is then applied to i​as in the previous example. Function r​is a form of syntactic sugar that displays a line break .

Among the other important functions of Unlambda are the functions k​and s​. k​Makes it possible to fabricate constant functions: thus `kxy​returns x when it is called, and ``kxy​always returns x , for all x and y .

s​Is a generalized evaluation operator. ```sxyz​Is evaluated as ``xy`z​for all x , y and z . It is remarkable that the functions s​and k​are sufficient to perform any computation, as shown by the SKI combinational computer. An example is an implementation of the function i​by ``skk​, since ```skkx​returns x for all x .

The control flow of Unlambda is the call with current continuation, noted c​. When an expression of the form `cx​is evaluated , a special continuation object is constructed that represents the state of the interpreter at that particular time. X is then evaluated , and the result is given to the continuation as an argument. If the continuation does not receive an argument, the value of the expression `cx​is identical to that of x . But if the continuation receives a value y , the execution of x is stopped, and the value of the whole expression `cx​is y .

Although the evaluation of Unlambda is normally strict , the operator activates d​a lazy evaluation option . Usually, to evaluate an expression of the form `xy​, Unlambda evaluates first x , then y , then applies x to y . However, if x has a value d​, y is not evaluated ; Instead, the value of the expression `dy​becomes a special object of delayed continuation which, applied to an object z , evaluates y , then applies it to z . It is noted that in the absence of side effects, it is equivalent to `iy​.`iy​`dy​

Notes and references

  1. ↑ ( in ) ” Good Math, Bad Math (blog): Friday Pathological Programming: unlambda, gold Without Programming Variables [ archive ]