Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Unlambda
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Original built-in functions== The notation <code>.''x''</code> denotes a function which takes one argument and returns it unchanged, printing the single character ''x'' as a side effect when it is invoked. <code>i</code> represents the version of the identity function that has no such side effect; it is used here as a dummy argument. The program <code>`.di</code> applies the <code>d</code>-printing function to a dummy argument of <code>i</code>, returning <code>i</code> and printing the letter <code>d</code> as a side effect. Similarly, <code>``.l.di</code> first applies <code>.l</code> to <code>.d</code>, printing the letter <code>l</code> and returning <code>.d</code>; this result of <code>.d</code> is then applied to <code>i</code> as in the previous example. The function <code>r</code> is [[syntactic sugar]] for the function that prints a newline character. Other important features provided by Unlambda include the <code>k</code> and <code>s</code> functions. <code>k</code> manufactures constant functions: the result of <code>`k''x''</code> is a function which, when invoked, returns ''x''. Thus the value of <code>``k''xy''</code> is ''x'' for any ''x'' and ''y''. <code>s</code> is a generalized evaluation operator. <code>```s''xyz''</code> evaluates to <code>``''xz''`''yz''</code> for any ''x'', ''y'', and ''z''. It is a remarkable fact that <code>s</code> and <code>k</code> are sufficient to perform any calculation, as described in [[SKI combinator calculus]]. As a brief example, the identity function <code>i</code> can be implemented as <code>``skk</code>, since <code>```skk''x''</code> yields ''x'' for all ''x''. Unlambda's one flow control construct is [[call with current continuation]], denoted <code>c</code>. When an expression of the form <code>`c''x''</code> 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 <code>`c''x''</code> 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 <code>`c''x''</code> expression is ''y''. Unlambda's execution semantics are normally [[eager evaluation]], but a [[lazy evaluation]] option exists, indicated by the use of the <code>d</code> operator. Usually, to evaluate an expression of the form <code>`''xy''</code>, unlambda first evaluates ''x'', then ''y'', and then applies ''x'' to ''y''. However, if ''x'' evaluates to the special value <code>d</code>, then ''y'' is ''not'' evaluated; instead, the value of the expression <code>`d''y''</code> 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 <code>`i''y''</code>. The difference is that <code>`i''y''</code> executes any side effects in ''y'' immediately, whereas <code>`d''y''</code> defers the side effects until the result is applied to another argument. Unlambda's next built-in operator is <code>v</code>, which ignores its argument and returns <code>v</code>. This feature is not strictly necessary, since <code>v</code> could be implemented as <code>``s`k``s``s`kskk`k``s``s`kskk</code>, but it is supplied as a convenience. (This expression above is simply <code>`Yk</code>, where <code>Y</code> denotes a [[fixed point combinator]].)
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)