(lispref.info)Intro Eval


Next: Eval Up: Evaluation

Introduction to Evaluation
==========================

   The Lisp interpreter, or evaluator, is the program which computes
the value of an expression which is given to it.  When a function
written in Lisp is called, the evaluator computes the value of the
function by evaluating the expressions in the function body.  Thus,
running any Lisp program really means running the Lisp interpreter.

   How the evaluator handles an object depends primarily on the data
type of the object.

   A Lisp object which is intended for evaluation is called an
"expression" or a "form".  The fact that expressions are data objects
and not merely text is one of the fundamental differences between
Lisp-like languages and typical programming languages.  Any object can
be evaluated, but in practice only numbers, symbols, lists and strings
are evaluated very often.

   It is very common to read a Lisp expression and then evaluate the
expression, but reading and evaluation are separate activities, and
either can be performed alone.  Reading per se does not evaluate
anything; it converts the printed representation of a Lisp object to the
object itself.  It is up to the caller of `read' whether this object is
a form to be evaluated, or serves some entirely different purpose.
Note: Input Functions.

   Do not confuse evaluation with command key interpretation.  The
editor command loop translates keyboard input into a command (an
interactively callable function) using the active keymaps, and then
uses `call-interactively' to invoke the command.  The execution of the
command itself involves evaluation if the command is written in Lisp,
but that is not a part of command key interpretation itself.  *Note
Command Loop::.

   Evaluation is a recursive process.  That is, evaluation of a form may
cause `eval' to be called again in order to evaluate parts of the form.
For example, evaluation of a function call first evaluates each
argument of the function call, and then evaluates each form in the
function body.  Consider evaluation of the form `(car x)': the subform
`x' must first be evaluated recursively, so that its value can be
passed as an argument to the function `car'.

   The evaluation of forms takes place in a context called the
"environment", which consists of the current values and bindings of all
Lisp variables.(1)  Whenever the form refers to a variable without
creating a new binding for it, the value of the binding in the current
environment is used.  Note: Variables.

   Evaluation of a form may create new environments for recursive
evaluation by binding variables (Note: Local Variables.).  These
environments are temporary and will be gone by the time evaluation of
the form is complete.  The form may also make changes that persist;
these changes are called "side effects".  An example of a form that
produces side effects is `(setq foo 1)'.

   Finally, evaluation of one particular function call, `byte-code',
invokes the "byte-code interpreter" on its arguments.  Although the
byte-code interpreter is not the same as the Lisp interpreter, it uses
the same environment as the Lisp interpreter, and may on occasion invoke
the Lisp interpreter.  (Note: Byte Compilation.)

   The details of what evaluation means for each kind of form are
described below (Note: Forms.).

   ---------- Footnotes ----------

   (1)  This definition of "environment" is specifically not intended
to include all the data which can affect the result of a program.


automatically generated by info2www