Unlambda
   HOME

TheInfoList



OR:

Unlambda is a minimal, "nearly
pure Pure may refer to: Computing * A pure function * A pure virtual function * PureSystems, a family of computer systems introduced by IBM in 2012 * Pure Software, a company founded in 1991 by Reed Hastings to support the Purify tool * Pure-FTPd, F ...
"
functional programming language In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that ...
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 (s and k) and an apply operator (written `, the backquote character). These alone make it
Turing-complete In computability theory, a system of data-manipulation rules (such as a computer's instruction set, a programming language, or a cellular automaton) is said to be Turing-complete or computationally universal if it can be used to simulate any ...
, but there are also some
input/output In computing, input/output (I/O, or informally io or IO) is the communication between an information processing system, such as a computer, and the outside world, possibly a human or another information processing system. Inputs are the signals ...
(I/O) functions to enable interacting with the user, some shortcut functions, and a
lazy evaluation In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is needed ( non-strict evaluation) and which also avoids repeated evaluations (sharing). The ...
function. Variables are unsupported. Unlambda is free and open-source software distributed under a
GNU General Public License The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the four freedoms to run, study, share, and modify the software. The license was the first copyleft for general ...
(GPL) 2.0 or later.


Basic principles

As an
esoteric programming language An esoteric programming language (sometimes shortened to esolang) is a programming language designed to test the boundaries of computer programming language design, as a proof of concept, as software art, as a hacking interface to another 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 object In programming language design, a first-class citizen (also type, object, entity, or value) in a given programming language is an entity which supports all the operations generally available to other entities. These operations typically include ...
s, and are the ''only'' such objects. Here is an implementation of a
hello world program ''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the '' Norwich ...
in Unlambda: `r```````````.H.e.l.l.o. .w.o.r.l.di


Original built-in functions

The notation .''x'' denotes a function which takes one argument and returns it unchanged, printing the single character ''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 In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. It makes the language "sweeter" for human use: things can be expressed more clearly, more concisely, or in an ...
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''x'' is a function which, when invoked, returns ''x''. Thus the value of ``k''xy'' is ''x'' for any ''x'' and ''y''. s is a generalized evaluation operator. ```s''xyz'' evaluates to ``''xz''`''yz'' for any ''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 The SKI combinator calculus is a combinatory logic system and a computational system. It can be thought of as a computer programming language, though it is not convenient for writing software. Instead, it is important in the mathematical theory o ...
. As a brief example, the identity function i can be implemented as ``skk, since ```skk''x'' yields ''x'' for all ''x''. Unlambda's one flow control construct is
call with current continuation In the Scheme (programming language), Scheme computer programming language, the procedure (computer science), procedure call-with-current-continuation, abbreviated call/cc, is used as a control flow operator. It has been adopted by several other p ...
, denoted c. When an expression of the form `c''x'' 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 `c''x'' 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 `c''x'' expression is ''y''. Unlambda's execution semantics are normally
eager evaluation In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the f ...
, but a
lazy evaluation In programming language theory, lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is needed ( non-strict evaluation) and which also avoids repeated evaluations (sharing). The ...
option exists, indicated by the use of the d operator. Usually, to evaluate an expression of the form `''xy'', unlambda first evaluates ''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''y'' 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 `i''y''. The difference is that `i''y'' executes any side effects in ''y'' immediately, whereas `d''y'' defers the side effects until the result is applied to another argument. 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 In mathematics and computer science in general, a '' fixed point'' of a function is a value that is mapped to itself by the function. In combinatory logic for computer science, a fixed-point combinator (or fixpoint combinator) is a higher-order ...
.)


Version 2 built-in functions

More built-ins were introduced in Unlambda version 2. Input is facilitated by operators @ and ?''u''. When @ 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 ?''u'' is applied to a function ''x'', the result is the evaluation of `''x''i if the current character is ''u'', otherwise `''x''v is evaluated. There is also a "reprint" operator , . When `, ''x'' is evaluated, the function ''x'' is applied to .''u'' if ''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).


See also

* Iota and Jot *
SKI combinator calculus The SKI combinator calculus is a combinatory logic system and a computational system. It can be thought of as a computer programming language, though it is not convenient for writing software. Instead, it is important in the mathematical theory o ...


References

* Felix-Hernandez Campos (1 April 2002),
Lecture 28: More on functional programming
', University of North Carolina COMP144 *


External links

*{{Official website, www.madore.org/~david/programs/unlambda
Online Unlambda REPL
Esoteric programming languages Functional languages