diff options
| author | Chong Yidong | 2009-02-23 17:43:28 +0000 |
|---|---|---|
| committer | Chong Yidong | 2009-02-23 17:43:28 +0000 |
| commit | a5b99fab3a802e4fec3dc0d86d70b656d4b01c3a (patch) | |
| tree | 30aa49c467edd7d46a6ec85d03ea5f36f4b49f3c /doc/lispref/eval.texi | |
| parent | 13e31e2bd1b073c72259afb945d8ad4980b8c565 (diff) | |
| download | emacs-a5b99fab3a802e4fec3dc0d86d70b656d4b01c3a.tar.gz emacs-a5b99fab3a802e4fec3dc0d86d70b656d4b01c3a.zip | |
(Intro Eval): Copyedits. Standardize on "form" instead of "expression" throughout.
(Function Indirection): Copyedits. Use active voice.
(Eval): The default value of max-lisp-eval-depth is now 400.
Diffstat (limited to 'doc/lispref/eval.texi')
| -rw-r--r-- | doc/lispref/eval.texi | 141 |
1 files changed, 68 insertions, 73 deletions
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi index 16b17b7e2f3..81b5c27d942 100644 --- a/doc/lispref/eval.texi +++ b/doc/lispref/eval.texi | |||
| @@ -30,75 +30,70 @@ function @code{eval}. | |||
| 30 | @node Intro Eval | 30 | @node Intro Eval |
| 31 | @section Introduction to Evaluation | 31 | @section Introduction to Evaluation |
| 32 | 32 | ||
| 33 | The Lisp interpreter, or evaluator, is the program that computes | 33 | The Lisp interpreter, or evaluator, is the part of Emacs that |
| 34 | the value of an expression that is given to it. When a function | 34 | computes the value of an expression that is given to it. When a |
| 35 | written in Lisp is called, the evaluator computes the value of the | 35 | function written in Lisp is called, the evaluator computes the value |
| 36 | function by evaluating the expressions in the function body. Thus, | 36 | of the function by evaluating the expressions in the function body. |
| 37 | running any Lisp program really means running the Lisp interpreter. | 37 | Thus, running any Lisp program really means running the Lisp |
| 38 | 38 | interpreter. | |
| 39 | How the evaluator handles an object depends primarily on the data | ||
| 40 | type of the object. | ||
| 41 | @end ifnottex | 39 | @end ifnottex |
| 42 | 40 | ||
| 43 | @cindex forms | 41 | @cindex form |
| 44 | @cindex expression | 42 | @cindex expression |
| 45 | A Lisp object that is intended for evaluation is called an | 43 | A Lisp object that is intended for evaluation is called an |
| 46 | @dfn{expression} or a @dfn{form}. The fact that expressions are data | 44 | @dfn{expression} or a @dfn{form}. The fact that forms are data |
| 47 | objects and not merely text is one of the fundamental differences | 45 | objects and not merely text is one of the fundamental differences |
| 48 | between Lisp-like languages and typical programming languages. Any | 46 | between Lisp-like languages and typical programming languages. Any |
| 49 | object can be evaluated, but in practice only numbers, symbols, lists | 47 | object can be evaluated, but in practice only numbers, symbols, lists |
| 50 | and strings are evaluated very often. | 48 | and strings are evaluated very often. |
| 51 | 49 | ||
| 52 | It is very common to read a Lisp expression and then evaluate the | 50 | In subsequent sections, we will describe the details of what |
| 53 | expression, but reading and evaluation are separate activities, and | 51 | evaluation means for each kind of form. |
| 54 | either can be performed alone. Reading per se does not evaluate | 52 | |
| 55 | anything; it converts the printed representation of a Lisp object to the | 53 | It is very common to read a Lisp form and then evaluate the form, |
| 56 | object itself. It is up to the caller of @code{read} whether this | 54 | but reading and evaluation are separate activities, and either can be |
| 55 | performed alone. Reading per se does not evaluate anything; it | ||
| 56 | converts the printed representation of a Lisp object to the object | ||
| 57 | itself. It is up to the caller of @code{read} to specify whether this | ||
| 57 | object is a form to be evaluated, or serves some entirely different | 58 | object is a form to be evaluated, or serves some entirely different |
| 58 | purpose. @xref{Input Functions}. | 59 | purpose. @xref{Input Functions}. |
| 59 | 60 | ||
| 60 | Do not confuse evaluation with command key interpretation. The | ||
| 61 | editor command loop translates keyboard input into a command (an | ||
| 62 | interactively callable function) using the active keymaps, and then | ||
| 63 | uses @code{call-interactively} to invoke the command. The execution of | ||
| 64 | the command itself involves evaluation if the command is written in | ||
| 65 | Lisp, but that is not a part of command key interpretation itself. | ||
| 66 | @xref{Command Loop}. | ||
| 67 | |||
| 68 | @cindex recursive evaluation | 61 | @cindex recursive evaluation |
| 69 | Evaluation is a recursive process. That is, evaluation of a form may | 62 | Evaluation is a recursive process, and evaluating a form often |
| 70 | call @code{eval} to evaluate parts of the form. For example, evaluation | 63 | involves evaluating parts within that form. For instance, when you |
| 71 | of a function call first evaluates each argument of the function call, | 64 | evaluate a @dfn{function call} form such as @code{(car x)}, Emacs |
| 72 | and then evaluates each form in the function body. Consider evaluation | 65 | first evaluates the argument (the subform @code{x}). After evaluating |
| 73 | of the form @code{(car x)}: the subform @code{x} must first be evaluated | 66 | the argument, Emacs @dfn{executes} the function (@code{car}), and if |
| 74 | recursively, so that its value can be passed as an argument to the | 67 | the function is written in Lisp, execution works by evaluating the |
| 75 | function @code{car}. | 68 | @dfn{body} of the function. (In this example, however, @code{car} is |
| 76 | 69 | not a Lisp function; it is a primitive function implemented in C.) | |
| 77 | Evaluation of a function call ultimately calls the function specified | 70 | @xref{Functions}, for more information about functions and function |
| 78 | in it. @xref{Functions}. The execution of the function may itself work | 71 | calls. |
| 79 | by evaluating the function definition; or the function may be a Lisp | ||
| 80 | primitive implemented in C, or it may be a byte-compiled function | ||
| 81 | (@pxref{Byte Compilation}). | ||
| 82 | 72 | ||
| 83 | @cindex environment | 73 | @cindex environment |
| 84 | The evaluation of forms takes place in a context called the | 74 | Evaluation takes place in a context called the @dfn{environment}, |
| 85 | @dfn{environment}, which consists of the current values and bindings of | 75 | which consists of the current values and bindings of all Lisp |
| 86 | all Lisp variables.@footnote{This definition of ``environment'' is | 76 | variables (@pxref{Variables}).@footnote{This definition of |
| 87 | specifically not intended to include all the data that can affect the | 77 | ``environment'' is specifically not intended to include all the data |
| 88 | result of a program.} Whenever a form refers to a variable without | 78 | that can affect the result of a program.} Whenever a form refers to a |
| 89 | creating a new binding for it, the value of the variable's binding in | 79 | variable without creating a new binding for it, the variable evaluates |
| 90 | the current environment is used. @xref{Variables}. | 80 | to the value given by the current environment. Evaluating a form may |
| 81 | create a new environment for recursive evaluation, by binding | ||
| 82 | variables (@pxref{Local Variables}). Such environments are temporary, | ||
| 83 | and vanish when the evaluation of the form is complete. | ||
| 91 | 84 | ||
| 92 | @cindex side effect | 85 | @cindex side effect |
| 93 | Evaluation of a form may create new environments for recursive | 86 | Evaluating a form may also make changes that persist; these changes |
| 94 | evaluation by binding variables (@pxref{Local Variables}). These | 87 | are called @dfn{side effects}. An example of a form that produces a |
| 95 | environments are temporary and vanish by the time evaluation of the form | 88 | side effect is @code{(setq foo 1)}. |
| 96 | is complete. The form may also make changes that persist; these changes | ||
| 97 | are called @dfn{side effects}. An example of a form that produces side | ||
| 98 | effects is @code{(setq foo 1)}. | ||
| 99 | 89 | ||
| 100 | The details of what evaluation means for each kind of form are | 90 | Do not confuse evaluation with command key interpretation. The |
| 101 | described below (@pxref{Forms}). | 91 | editor command loop translates keyboard input into a command (an |
| 92 | interactively callable function) using the active keymaps, and then | ||
| 93 | uses @code{call-interactively} to execute that command. Executing the | ||
| 94 | command usually involves evaluation, if the command is written in | ||
| 95 | Lisp; however, this step is not considered a part of command key | ||
| 96 | interpretation. @xref{Command Loop}. | ||
| 102 | 97 | ||
| 103 | @node Forms | 98 | @node Forms |
| 104 | @section Kinds of Forms | 99 | @section Kinds of Forms |
| @@ -130,13 +125,13 @@ forms. | |||
| 130 | @cindex literal evaluation | 125 | @cindex literal evaluation |
| 131 | @cindex self-evaluating form | 126 | @cindex self-evaluating form |
| 132 | 127 | ||
| 133 | A @dfn{self-evaluating form} is any form that is not a list or symbol. | 128 | A @dfn{self-evaluating form} is any form that is not a list or |
| 134 | Self-evaluating forms evaluate to themselves: the result of evaluation | 129 | symbol. Self-evaluating forms evaluate to themselves: the result of |
| 135 | is the same object that was evaluated. Thus, the number 25 evaluates to | 130 | evaluation is the same object that was evaluated. Thus, the number 25 |
| 136 | 25, and the string @code{"foo"} evaluates to the string @code{"foo"}. | 131 | evaluates to 25, and the string @code{"foo"} evaluates to the string |
| 137 | Likewise, evaluation of a vector does not cause evaluation of the | 132 | @code{"foo"}. Likewise, evaluating a vector does not cause evaluation |
| 138 | elements of the vector---it returns the same vector with its contents | 133 | of the elements of the vector---it returns the same vector with its |
| 139 | unchanged. | 134 | contents unchanged. |
| 140 | 135 | ||
| 141 | @example | 136 | @example |
| 142 | @group | 137 | @group |
| @@ -236,13 +231,12 @@ Scheme. | |||
| 236 | @cindex indirection for functions | 231 | @cindex indirection for functions |
| 237 | @cindex void function | 232 | @cindex void function |
| 238 | 233 | ||
| 239 | If the first element of the list is a symbol then evaluation examines | 234 | If the first element of the list is a symbol then evaluation |
| 240 | the symbol's function cell, and uses its contents instead of the | 235 | examines the symbol's function cell, and uses its contents instead of |
| 241 | original symbol. If the contents are another symbol, this process, | 236 | the original symbol. If the contents are another symbol, this |
| 242 | called @dfn{symbol function indirection}, is repeated until it obtains a | 237 | process, called @dfn{symbol function indirection}, is repeated until |
| 243 | non-symbol. @xref{Function Names}, for more information about using a | 238 | it obtains a non-symbol. @xref{Function Names}, for more information |
| 244 | symbol as a name for a function stored in the function cell of the | 239 | about symbol function indirection. |
| 245 | symbol. | ||
| 246 | 240 | ||
| 247 | One possible consequence of this process is an infinite loop, in the | 241 | One possible consequence of this process is an infinite loop, in the |
| 248 | event that a symbol's function cell refers to the same symbol. Or a | 242 | event that a symbol's function cell refers to the same symbol. Or a |
| @@ -253,10 +247,10 @@ which ought to be a function or other suitable object. | |||
| 253 | 247 | ||
| 254 | @kindex invalid-function | 248 | @kindex invalid-function |
| 255 | More precisely, we should now have a Lisp function (a lambda | 249 | More precisely, we should now have a Lisp function (a lambda |
| 256 | expression), a byte-code function, a primitive function, a Lisp macro, a | 250 | expression), a byte-code function, a primitive function, a Lisp macro, |
| 257 | special form, or an autoload object. Each of these types is a case | 251 | a special form, or an autoload object. Each of these types is a case |
| 258 | described in one of the following sections. If the object is not one of | 252 | described in one of the following sections. If the object is not one |
| 259 | these types, the error @code{invalid-function} is signaled. | 253 | of these types, Emacs signals an @code{invalid-function} error. |
| 260 | 254 | ||
| 261 | The following example illustrates the symbol indirection process. We | 255 | The following example illustrates the symbol indirection process. We |
| 262 | use @code{fset} to set the function cell of a symbol and | 256 | use @code{fset} to set the function cell of a symbol and |
| @@ -695,10 +689,11 @@ The depth limit counts internal uses of @code{eval}, @code{apply}, and | |||
| 695 | expressions, and recursive evaluation of function call arguments and | 689 | expressions, and recursive evaluation of function call arguments and |
| 696 | function body forms, as well as explicit calls in Lisp code. | 690 | function body forms, as well as explicit calls in Lisp code. |
| 697 | 691 | ||
| 698 | The default value of this variable is 300. If you set it to a value | 692 | The default value of this variable is 400. If you set it to a value |
| 699 | less than 100, Lisp will reset it to 100 if the given value is reached. | 693 | less than 100, Lisp will reset it to 100 if the given value is |
| 700 | Entry to the Lisp debugger increases the value, if there is little room | 694 | reached. Entry to the Lisp debugger increases the value, if there is |
| 701 | left, to make sure the debugger itself has room to execute. | 695 | little room left, to make sure the debugger itself has room to |
| 696 | execute. | ||
| 702 | 697 | ||
| 703 | @code{max-specpdl-size} provides another limit on nesting. | 698 | @code{max-specpdl-size} provides another limit on nesting. |
| 704 | @xref{Definition of max-specpdl-size,, Local Variables}. | 699 | @xref{Definition of max-specpdl-size,, Local Variables}. |