In
Lisp
A lisp is a speech impairment in which a person misarticulates sibilants (, , , , , , , ). These misarticulations often result in unclear speech.
Types
* A frontal lisp occurs when the tongue is placed anterior to the target. Interdental lispi ...
programming languages, a fexpr is a function whose operands are passed to it without being evaluated. When a fexpr is called, only the body of the fexpr is evaluated; no other evaluations take place except when explicitly initiated by the fexpr. In contrast, when an ordinary Lisp function is called, the operands are evaluated automatically, and only the results of these evaluations are provided to the function; and when a (traditional)
Lisp macro is called, the operands are passed in unevaluated, but whatever result the macro function returns is automatically evaluated.
Origin of the name "fexpr"
In early Lisp, the environment mapped each symbol to an
association list, rather than directly to a value.
[McCarthy et al., ''Lisp I Programmer's Manual'', pp. 88–91.] Standard keys for these lists included two keys used to store a data value, to be looked up when the symbol occurred as an argument ( and ); and four keys used to store a function, to be looked up when the symbol occurred as an operator. Of the function keys, indicated a compiled ordinary function, whose operands were evaluated and passed to it; indicated a compiled special form, whose operands were passed unevaluated; indicated a user-defined ordinary function; and indicated a user-defined special form. The only difference between a FEXPR and an EXPR was whether the operands were automatically evaluated.
In strict original usage, a FEXPR is therefore a user-defined function whose operands are passed unevaluated. However, in later usage the term ''fexpr'' may describe any
first-class function
In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. This means the language supports passing functions as arguments to other functions, returning them as the values from ...
whose operands are passed unevaluated, regardless of whether the function is primitive or user-defined.
[Pitman, ''The Revised MacLisp Manual'', p. 75.]
Example
As a simple illustration of how fexprs work, here is a fexpr definition written in the
Kernel programming language, which is similar to
Scheme. (By convention in Kernel, the names of fexprs always start with .)
($define! $f
($vau (x y z) e
($if (>=? (eval x e) 0)
(eval y e)
(eval z e))))
This definition provides a fexpr called , which takes three operands. When the fexpr is called, a local
environment
Environment most often refers to:
__NOTOC__
* Natural environment, all living and non-living things occurring naturally
* Biophysical environment, the physical and biological factors along with their chemical interactions that affect an organism or ...
is created by extending the static environment where the fexpr was defined. Local bindings are then created: symbols , , and are bound to the three operands of the call to the fexpr, and symbol is bound to the dynamic environment from which the fexpr is being called. The body of the fexpr, ..., is then evaluated in this local environment, and the result of that evaluation becomes the result of the call to the fexpr. The net effect is that the first operand is evaluated in the dynamic environment, and, depending on whether the result of that evaluation is non-negative, either the second or the third operand is evaluated and that result returned. The other operand, either the third or the second, is not evaluated.
This example is
statically scoped: the local environment is an extension of the static environment. Before about 1980, the Lisp languages that supported fexprs were mainly dynamically scoped: the local environment was an extension of the dynamic environment, rather than of the static environment.
[Steele and Gabriel, "The Evolution of Lisp", pp. 239–240.] However, it was still sometimes necessary to provide a local name for the dynamic environment, to avoid
capturing the local parameter names.
[Pitman, ''The Revised MacLisp Manual'', p. 62]
Mainstream use and deprecation
Fexpr support continued in
Lisp 1.5
Lisp (historically LISP) is a family of programming languages with a long history and a distinctive, fully parenthesized prefix notation.
Originally specified in 1960, Lisp is the second-oldest high-level programming language still in common us ...
, the last substantially standard dialect of Lisp before it fragmented into multiple languages.
[Steele and Gabriel, "The Evolution of Lisp", pp. 231-232.] In the 1970s, the two dominant Lisp languages
[Steele and Gabriel, "The Evolution of Lisp", p. 235.] —
MacLisp and
Interlisp
Interlisp (also seen with a variety of capitalizations) is a programming environment built around a version of the programming language Lisp. Interlisp development began in 1966 at Bolt, Beranek and Newman (renamed BBN Technologies) in Cambridge, ...
— both supported fexprs.
[Pitman, ''The Revised MacLisp Manual'', p. 182.]
At the 1980
Conference on Lisp and Functional Programming,
Kent Pitman presented a paper "Special Forms in Lisp" in which he discussed the advantages and disadvantages of macros and fexprs, and ultimately condemned fexprs. His central objection was that, in a Lisp dialect that allows fexprs,
static analysis cannot determine generally whether an operator represents an ordinary function or a fexpr — therefore, static analysis cannot determine whether or not the operands will be evaluated. In particular, the compiler cannot tell whether a subexpression can be safely optimized, since the subexpression might be treated as unevaluated data at run-time.
Since the decline of MacLisp and Interlisp, the two Lisp languages that had risen to dominance by 1993
[Steele and Gabriel, "The Evolution of Lisp", pp. 245–248] —
Scheme and
Common Lisp
Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fr ...
— do not support fexprs.
newLISP
newLISP is a scripting language which is a dialect of the Lisp family of programming languages. It was designed and developed by Lutz Mueller. newLISP is free and open-source software released under the GNU General Public License, version 3 or ...
does support fexprs, but calls them "macros". In
Picolisp
PicoLisp is a programming language, a dialect of the language Lisp. It runs on operating systems including Linux and others that are ''Portable Operating System Interface'' (POSIX) compliant. Its most prominent features are simplicity and minimali ...
all built-in functions are , while Lisp-level functions are exprs, fexprs, , or a mixture of those.
Fexprs since 1980
Starting with
Brian Smith's
3-Lisp in 1982, several experimental Lisp dialects have been devised to explore the limits of
computational reflection
In computer science, reflective programming or reflection is the ability of a process to examine, introspect, and modify its own structure and behavior.
Historical background
The earliest computers were programmed in their native assembly lan ...
. To support reflection, these Lisps support procedures that can
reify various data structures related to the call to them — including the unevaluated operands of the call, which makes these procedures fexprs. By the late 1990s, fexprs had become associated primarily with computational reflection.
[Wand, "The Theory of Fexprs is Trivial", p. 189.]
Some theoretical results on fexprs have been obtained. In 1993, John C. Mitchell used Lisp with fexprs as an example of a programming language whose source expressions cannot be formally abstract (because the concrete syntax of a source expression can always be extracted by a context in which it is an operand to a fexpr).
[Mitchell, "On Abstraction and the Expressive Power of Programming Languages", section 7.] In 1998,
Mitchell Wand showed that adding a fexpr device to
lambda calculus
Lambda calculus (also written as ''λ''-calculus) is a formal system in mathematical logic for expressing computation based on function abstraction and application using variable binding and substitution. It is a universal model of computation t ...
— a device that suppresses rewriting of operands — produces a
formal system
A formal system is an abstract structure used for inferring theorems from axioms according to a set of rules. These rules, which are used for carrying out the inference of theorems from axioms, are the logical calculus of the formal system.
A for ...
with a trivial equational
theory
A theory is a rational type of abstract thinking about a phenomenon, or the results of such thinking. The process of contemplative and rational thinking is often associated with such processes as observational study or research. Theories may ...
, rendering it impossible to make source-to-source optimizations without a
whole-program analysis.
In 2007, John N. Shutt proposed an extension of lambda calculus that would model fexprs without suppressing rewriting of operands, avoiding Wand's result.
[Shutt, "vau-calculi and the theory of fexprs".]
See also
*
ISWIM
*
DWIM
The following languages implement fexprs or near equivalents:
* the
ECL programming language provides parameter type ("bind-class")
UNEVAL
, which specifies that a
syntax tree Syntax tree may refer to:
* Abstract syntax tree, used in computer science
* Concrete syntax tree, used in linguistics
{{Disambig ...
for the argument expression is to be bound to the parameter.
*
io, methods (blocks) can use introspection, using
call
to refer to the entire call and manipulate that. Se
call and self slots in io
*
Kernel
Kernel may refer to:
Computing
* Kernel (operating system), the central component of most operating systems
* Kernel (image processing), a matrix used for image convolution
* Compute kernel, in GPGPU programming
* Kernel method, in machine lea ...
uses
$vau
to create fexprs, similar to how
lambda
creates functions in
Scheme.
*
newLISP
newLISP is a scripting language which is a dialect of the Lisp family of programming languages. It was designed and developed by Lutz Mueller. newLISP is free and open-source software released under the GNU General Public License, version 3 or ...
uses
define-macro
to define fexprs. Se
section "Fexpr macros and rewrite macros"
* In
PicoLisp
PicoLisp is a programming language, a dialect of the language Lisp. It runs on operating systems including Linux and others that are ''Portable Operating System Interface'' (POSIX) compliant. Its most prominent features are simplicity and minimali ...
,
(de foo X ...)
defines an fexpr
foo
that when called binds
X
to the list of unevaluated argument expressions. Se
Evaluation in PicoLisp
*
R parameters are generally bound to
promises
A promise is a transaction whereby a person makes a vow or the suggestion of a guarantee.
Promise(s) may also refer to:
Places
* Promise, Oregon
*Promise, South Dakota
*Promise City, Iowa
*Promise Land, Tennessee or Promise
Film and TV
* ''Pro ...
(resulting in
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).
T ...
), and calling
substitute(param)
on a parameter yields the argument expression, se
Substitutions in R
* In
REBOL, argument expressions not to be evaluated need to be wrapped in a block (square brackets) by the caller. In other words, you can not define a callee that prevents argument evaluation. Se
this articlewith examples. In this sense, REBOL does not have fexprs, it just makes it easy to emulate some of their uses. In a language with true fexprs, fexpr calls look like normal function calls. In REBOL on the other hand, calls where the arguments are not evaluated always look different from normal function calls.
Footnotes
References
* Accessed May 11, 2010.
* John C. Mitchell
''Science of Computer Programming'' 212 (1993), pp. 141–163. (Special issue of papers from Symp. Theor. Aspects of Computer Software, Sendai, Japan, 1991.) Accessed January 24, 2008.
* Kent M. Pitman
Proceedings of the 1980 ACM Conference on Lisp and Functional Programming, 1980, pp. 179–187. Accessed January 25, 2008.
* Kent M. Pitman, ''The Revised MacLisp Manual'' (Saturday evening edition), MIT Laboratory for Computer Science Technical Report 295, May 21, 1983.
* John N. Shutt, "vau-calculi and the theory of fexprs", talk
New England Programming Languages and Systems Symposium Series (NEPLS) October 18, 2007
accessed January 27, 2008.
* Guy L. Steele and Richard P. Gabriel, "The Evolution of Lisp", ''ACM SIGPLAN Notices'' 28 no. 3 (March 1993), pp. 231–270.
* Mitchell Wand
''Lisp and Symbolic Computation'' 10 no. 3 (May 1998), pp. 189–199. Accessed January 25, 2008.
{{refend
Lisp (programming language)
Programming constructs