aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2009-02-23 17:43:28 +0000
committerChong Yidong2009-02-23 17:43:28 +0000
commita5b99fab3a802e4fec3dc0d86d70b656d4b01c3a (patch)
tree30aa49c467edd7d46a6ec85d03ea5f36f4b49f3c
parent13e31e2bd1b073c72259afb945d8ad4980b8c565 (diff)
downloademacs-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.
-rw-r--r--doc/lispref/eval.texi141
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
34the value of an expression that is given to it. When a function 34computes the value of an expression that is given to it. When a
35written in Lisp is called, the evaluator computes the value of the 35function written in Lisp is called, the evaluator computes the value
36function by evaluating the expressions in the function body. Thus, 36of the function by evaluating the expressions in the function body.
37running any Lisp program really means running the Lisp interpreter. 37Thus, running any Lisp program really means running the Lisp
38 38interpreter.
39 How the evaluator handles an object depends primarily on the data
40type 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
47objects and not merely text is one of the fundamental differences 45objects and not merely text is one of the fundamental differences
48between Lisp-like languages and typical programming languages. Any 46between Lisp-like languages and typical programming languages. Any
49object can be evaluated, but in practice only numbers, symbols, lists 47object can be evaluated, but in practice only numbers, symbols, lists
50and strings are evaluated very often. 48and 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
53expression, but reading and evaluation are separate activities, and 51evaluation means for each kind of form.
54either can be performed alone. Reading per se does not evaluate 52
55anything; 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,
56object itself. It is up to the caller of @code{read} whether this 54but reading and evaluation are separate activities, and either can be
55performed alone. Reading per se does not evaluate anything; it
56converts the printed representation of a Lisp object to the object
57itself. It is up to the caller of @code{read} to specify whether this
57object is a form to be evaluated, or serves some entirely different 58object is a form to be evaluated, or serves some entirely different
58purpose. @xref{Input Functions}. 59purpose. @xref{Input Functions}.
59 60
60 Do not confuse evaluation with command key interpretation. The
61editor command loop translates keyboard input into a command (an
62interactively callable function) using the active keymaps, and then
63uses @code{call-interactively} to invoke the command. The execution of
64the command itself involves evaluation if the command is written in
65Lisp, 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
70call @code{eval} to evaluate parts of the form. For example, evaluation 63involves evaluating parts within that form. For instance, when you
71of a function call first evaluates each argument of the function call, 64evaluate a @dfn{function call} form such as @code{(car x)}, Emacs
72and then evaluates each form in the function body. Consider evaluation 65first evaluates the argument (the subform @code{x}). After evaluating
73of the form @code{(car x)}: the subform @code{x} must first be evaluated 66the argument, Emacs @dfn{executes} the function (@code{car}), and if
74recursively, so that its value can be passed as an argument to the 67the function is written in Lisp, execution works by evaluating the
75function @code{car}. 68@dfn{body} of the function. (In this example, however, @code{car} is
76 69not 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
78in it. @xref{Functions}. The execution of the function may itself work 71calls.
79by evaluating the function definition; or the function may be a Lisp
80primitive 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 75which consists of the current values and bindings of all Lisp
86all Lisp variables.@footnote{This definition of ``environment'' is 76variables (@pxref{Variables}).@footnote{This definition of
87specifically not intended to include all the data that can affect the 77``environment'' is specifically not intended to include all the data
88result of a program.} Whenever a form refers to a variable without 78that can affect the result of a program.} Whenever a form refers to a
89creating a new binding for it, the value of the variable's binding in 79variable without creating a new binding for it, the variable evaluates
90the current environment is used. @xref{Variables}. 80to the value given by the current environment. Evaluating a form may
81create a new environment for recursive evaluation, by binding
82variables (@pxref{Local Variables}). Such environments are temporary,
83and 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
94evaluation by binding variables (@pxref{Local Variables}). These 87are called @dfn{side effects}. An example of a form that produces a
95environments are temporary and vanish by the time evaluation of the form 88side effect is @code{(setq foo 1)}.
96is complete. The form may also make changes that persist; these changes
97are called @dfn{side effects}. An example of a form that produces side
98effects 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
101described below (@pxref{Forms}). 91editor command loop translates keyboard input into a command (an
92interactively callable function) using the active keymaps, and then
93uses @code{call-interactively} to execute that command. Executing the
94command usually involves evaluation, if the command is written in
95Lisp; however, this step is not considered a part of command key
96interpretation. @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
134Self-evaluating forms evaluate to themselves: the result of evaluation 129symbol. Self-evaluating forms evaluate to themselves: the result of
135is the same object that was evaluated. Thus, the number 25 evaluates to 130evaluation is the same object that was evaluated. Thus, the number 25
13625, and the string @code{"foo"} evaluates to the string @code{"foo"}. 131evaluates to 25, and the string @code{"foo"} evaluates to the string
137Likewise, evaluation of a vector does not cause evaluation of the 132@code{"foo"}. Likewise, evaluating a vector does not cause evaluation
138elements of the vector---it returns the same vector with its contents 133of the elements of the vector---it returns the same vector with its
139unchanged. 134contents 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
240the symbol's function cell, and uses its contents instead of the 235examines the symbol's function cell, and uses its contents instead of
241original symbol. If the contents are another symbol, this process, 236the original symbol. If the contents are another symbol, this
242called @dfn{symbol function indirection}, is repeated until it obtains a 237process, called @dfn{symbol function indirection}, is repeated until
243non-symbol. @xref{Function Names}, for more information about using a 238it obtains a non-symbol. @xref{Function Names}, for more information
244symbol as a name for a function stored in the function cell of the 239about symbol function indirection.
245symbol.
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
248event that a symbol's function cell refers to the same symbol. Or a 242event 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
256expression), a byte-code function, a primitive function, a Lisp macro, a 250expression), a byte-code function, a primitive function, a Lisp macro,
257special form, or an autoload object. Each of these types is a case 251a special form, or an autoload object. Each of these types is a case
258described in one of the following sections. If the object is not one of 252described in one of the following sections. If the object is not one
259these types, the error @code{invalid-function} is signaled. 253of 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
262use @code{fset} to set the function cell of a symbol and 256use @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
695expressions, and recursive evaluation of function call arguments and 689expressions, and recursive evaluation of function call arguments and
696function body forms, as well as explicit calls in Lisp code. 690function body forms, as well as explicit calls in Lisp code.
697 691
698The default value of this variable is 300. If you set it to a value 692The default value of this variable is 400. If you set it to a value
699less than 100, Lisp will reset it to 100 if the given value is reached. 693less than 100, Lisp will reset it to 100 if the given value is
700Entry to the Lisp debugger increases the value, if there is little room 694reached. Entry to the Lisp debugger increases the value, if there is
701left, to make sure the debugger itself has room to execute. 695little room left, to make sure the debugger itself has room to
696execute.
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}.