This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Unlambda" – news ·newspapers ·books ·scholar ·JSTOR(August 2020) (Learn how and when to remove this message) |
| Unlambda | |
|---|---|
| Paradigm | Nearlypurefunctional |
| Designed by | David Madore |
| Developer | David Madore |
| First appeared | 28 June 1999; 26 years ago (1999-06-28) |
| Stable release | 2.0.0 / 20 December 1999; 26 years ago (1999-12-20) |
| Typing discipline | Untyped |
| Implementation language | Scheme,C,Java |
| License | GPL 2.0 or later |
| Website | www |
Unlambda is a minimal, "nearlypure"[1]functional programming language invented by David Madore. It is based oncombinatory logic, an expression system without thelambda operator or free variables. It relies mainly on two built-in functions (s andk) and an apply operator (written`, thebackquote character). These alone make itTuring-complete, but there are also someinput/output (I/O) functions to enable interacting with the user, some shortcut functions, and alazy evaluation function. Variables are unsupported.
Unlambda isfree and open-source software distributed under aGNU General Public License (GPL) 2.0 or later.[clarification needed]
As anesoteric 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 thelambda calculus. Multi-parameter functions can be represented via the method ofcurrying.
Unlambda is based on the principle ofabstraction elimination, or the elimination of all saved variables, including functions. As a purely functional language, Unlambda's functions arefirst-class objects, and are theonly such objects.
Here is an implementation of ahello world program in Unlambda:[1]
`r```````````.H.e.l.l.o. .w.o.r.l.di
The notation.x denotes a function which takes one argument and returns it unchanged, printing the single characterx 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 thed-printing function to a dummy argument ofi, returningi and printing the letterd as a side effect. Similarly,``.l.di first applies.l to.d, printing the letterl and returning.d; this result of.d is then applied toi as in the previous example. The functionr issyntactic sugar for the function that prints a newline character.
Other important features provided by Unlambda include thek ands functions.k manufactures constant functions: the result of`kx is a function which, when invoked, returnsx. Thus the value of``kxy isx for anyx andy.
s is a generalized evaluation operator.```sxyz evaluates to``xz`yz for anyx,y, andz. It is a remarkable fact thats andk are sufficient to perform any calculation, as described inSKI combinator calculus. As a brief example, the identity functioni can be implemented as``skk, since```skkx yieldsx for allx.
Unlambda's one flow control construct iscall with current continuation, denotedc. When an expression of the form`cx is evaluated, a specialcontinuation object is constructed, representing the state of the interpreter at that moment. Thenx 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`cx expression is the same as the value ofx. But if the continuation object is applied to a valuey, execution ofx is immediately aborted, and the value of the entire`cx expression isy.
Unlambda's execution semantics are normallyeager evaluation, but alazy evaluation option exists, indicated by the use of thed operator. Usually, to evaluate an expression of the form`xy, unlambda first evaluatesx, theny, and then appliesx toy. However, ifx evaluates to the special valued, theny isnot evaluated; instead, the value of the expression`dy is a special "delayed computation" object, which, when applied to an argumentz, evaluatesy, and then applies its value toz. In the absence of side effects, this is exactly the same as`iy. The difference is that`iy executes any side effects iny immediately, whereas`dy defers the side effects until the result is applied to another argument.
Unlambda's next built-in operator isv, which ignores its argument and returnsv. This feature is not strictly necessary, sincev 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, whereY denotes afixed point combinator.)
More built-ins were introduced in Unlambda version 2.Input is facilitated by operators@ and?u. When@ is applied to a functionx, a character is read from input, and stored as the "current character"; thenx is applied toi. However, if no more characters were available on input, thecurrent character is left undefined, andx is applied tov instead. When a function?u is applied to a functionx, the result is the evaluation of`xi if the current character isu, otherwise`xv is evaluated.
There is also a "reprint" operator|. When`|x is evaluated, the functionx is applied to.u ifu is the current character, or tov if there is no current character.
Finally, there is an exit operatore. Whene is applied tox, the execution of the program is terminated, andx is taken as the result of the program (most of the currently existing interpreters ignore the result anyway).
{{cite book}}: CS1 maint: publisher location (link)