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 :
indicates a function taking an argument and returning it unchanged, with the side effect of displaying the character x when called.
Is a version of the identity function that does not have this side effect. It is therefore used as a fictitious parameter. The code
applies the display to the fictitious
doing so. Similarly,
, which is then applied to
as in the previous example. Function
is a form of syntactic sugar that displays a line break .
Among the other important functions of Unlambda are the functions
Makes it possible to fabricate constant functions: thus
returns x when it is called, and
always returns x , for all x and y .
Is a generalized evaluation operator.
Is evaluated as
for all x , y and z . It is remarkable that the functions
are sufficient to perform any computation, as shown by the SKI combinational computer. An example is an implementation of the function
returns x for all x .
The control flow of Unlambda is the call with current continuation, noted
. When an expression of the form
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
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
is y .
Although the evaluation of Unlambda is normally strict , the operator activates
a lazy evaluation option . Usually, to evaluate an expression of the form
, Unlambda evaluates first x , then y , then applies x to y . However, if x has a value
, y is not evaluated ; Instead, the value of the expression
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
Notes and references
- ↑ ( in ) ” Good Math, Bad Math (blog): Friday Pathological Programming: unlambda, gold Without Programming Variables ” [ archive ]