Introduction to Evaluation ========================== The Lisp interpreter, or evaluator, is the program that computes the value of an expression that 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 that 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 call `eval' 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'. Evaluation of a function call ultimately calls the function specified in it. Note: Functions. The execution of the function may itself work by evaluating the function definition; or the function may be a Lisp primitive implemented in C, or it may be a byte-compiled function (Note: Byte Compilation). 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 a form refers to a variable without creating a new binding for it, the value of the variable's 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 vanish 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)'. 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 that can affect the result of a program.
automatically generated by info2www version 188.8.131.52