comparison man/lispref/control.texi @ 5361:62b9ef1ed4ac

Change "special form" to "special operator" in the manuals, too 2011-03-01 Aidan Kehoe <kehoea@parhasard.net> * lispref/commands.texi (Using Interactive): * lispref/compile.texi (Eval During Compile): * lispref/compile.texi (Compiled-Function Objects): * lispref/control.texi (Sequencing): * lispref/control.texi (Conditionals): * lispref/control.texi (Combining Conditions): * lispref/control.texi (Iteration): * lispref/control.texi (Catch and Throw): * lispref/control.texi (Handling Errors): * lispref/control.texi (Cleanups): * lispref/display.texi (Temporary Displays): * lispref/eval.texi (Quoting): * lispref/eval.texi (Multiple values): * lispref/frames.texi (Input Focus): * lispref/functions.texi (Argument List): * lispref/functions.texi (Defining Functions): * lispref/functions.texi (Anonymous Functions): * lispref/internationalization.texi (Level 3 Primitives): * lispref/internationalization.texi (Domain Specification): * lispref/intro.texi (A Sample Function Description): * lispref/intro.texi (A Sample Variable Description): * lispref/lists.texi (Sets And Lists): * lispref/macros.texi (Defining Macros): * lispref/macros.texi (Backquote): * lispref/positions.texi (Excursions): * lispref/positions.texi (Narrowing): * lispref/searching.texi (Saving Match Data): * lispref/sequences.texi (Sequence Functions): * lispref/sequences.texi (Array Functions): * lispref/specifiers.texi (Adding Specifications): * lispref/variables.texi (Local Variables): * lispref/variables.texi (Defining Variables): * lispref/variables.texi (Setting Variables): * lispref/variables.texi (Default Value): * lispref/windows.texi (Selecting Windows): * lispref/windows.texi (Window Configurations): No longer use @defspec, since we no longer use the term "special form"; instead use @deffn {Special Operator}. Unfortunately there's no way in texinfo to redefine @defspec in one place.
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 01 Mar 2011 14:18:45 +0000
parents 755ae5b97edb
children 9fae6227ede5
comparison
equal deleted inserted replaced
5359:f5a5501814f5 5361:62b9ef1ed4ac
74 Many other control structures likewise contain an implicit @code{progn}. 74 Many other control structures likewise contain an implicit @code{progn}.
75 As a result, @code{progn} is not used as often as it used to be. It is 75 As a result, @code{progn} is not used as often as it used to be. It is
76 needed now most often inside an @code{unwind-protect}, @code{and}, 76 needed now most often inside an @code{unwind-protect}, @code{and},
77 @code{or}, or in the @var{then}-part of an @code{if}. 77 @code{or}, or in the @var{then}-part of an @code{if}.
78 78
79 @defspec progn forms@dots{} 79 @deffn {Special Operator} progn forms@dots{}
80 This special operator evaluates all of the @var{forms}, in textual 80 This special operator evaluates all of the @var{forms}, in textual
81 order, returning the result of the final form. 81 order, returning the result of the final form.
82 82
83 @example 83 @example
84 @group 84 @group
89 @print{} "The second form" 89 @print{} "The second form"
90 @print{} "The third form" 90 @print{} "The third form"
91 @result{} "The third form" 91 @result{} "The third form"
92 @end group 92 @end group
93 @end example 93 @end example
94 @end defspec 94 @end deffn
95 95
96 Two other control constructs likewise evaluate a series of forms but return 96 Two other control constructs likewise evaluate a series of forms but return
97 a different value: 97 a different value:
98 98
99 @defspec prog1 form1 forms@dots{} 99 @deffn {Special Operator} prog1 form1 forms@dots{}
100 This special operator evaluates @var{form1} and all of the @var{forms}, in 100 This special operator evaluates @var{form1} and all of the @var{forms}, in
101 textual order, returning the result of @var{form1}. 101 textual order, returning the result of @var{form1}.
102 102
103 @example 103 @example
104 @group 104 @group
116 @code{x}, then return the value of that former element: 116 @code{x}, then return the value of that former element:
117 117
118 @example 118 @example
119 (prog1 (car x) (setq x (cdr x))) 119 (prog1 (car x) (setq x (cdr x)))
120 @end example 120 @end example
121 @end defspec 121 @end deffn
122 122
123 @defspec prog2 form1 form2 forms@dots{} 123 @deffn {Special Operator} prog2 form1 form2 forms@dots{}
124 This special operator evaluates @var{form1}, @var{form2}, and all of the 124 This special operator evaluates @var{form1}, @var{form2}, and all of the
125 following @var{forms}, in textual order, returning the result of 125 following @var{forms}, in textual order, returning the result of
126 @var{form2}. 126 @var{form2}.
127 127
128 @example 128 @example
134 @print{} "The second form" 134 @print{} "The second form"
135 @print{} "The third form" 135 @print{} "The third form"
136 @result{} "The second form" 136 @result{} "The second form"
137 @end group 137 @end group
138 @end example 138 @end example
139 @end defspec 139 @end deffn
140 140
141 @node Conditionals 141 @node Conditionals
142 @section Conditionals 142 @section Conditionals
143 @cindex conditional evaluation 143 @cindex conditional evaluation
144 144
145 Conditional control structures choose among alternatives. XEmacs Lisp 145 Conditional control structures choose among alternatives. XEmacs Lisp
146 has two conditional forms: @code{if}, which is much the same as in other 146 has two conditional forms: @code{if}, which is much the same as in other
147 languages, and @code{cond}, which is a generalized case statement. 147 languages, and @code{cond}, which is a generalized case statement.
148 148
149 @defspec if condition then-form else-forms@dots{} 149 @deffn {Special Operator} if condition then-form else-forms@dots{}
150 @code{if} chooses between the @var{then-form} and the @var{else-forms} 150 @code{if} chooses between the @var{then-form} and the @var{else-forms}
151 based on the value of @var{condition}. If the evaluated @var{condition} is 151 based on the value of @var{condition}. If the evaluated @var{condition} is
152 non-@code{nil}, @var{then-form} is evaluated and the result returned. 152 non-@code{nil}, @var{then-form} is evaluated and the result returned.
153 Otherwise, the @var{else-forms} are evaluated in textual order, and the 153 Otherwise, the @var{else-forms} are evaluated in textual order, and the
154 value of the last one is returned. (The @var{else} part of @code{if} is 154 value of the last one is returned. (The @var{else} part of @code{if} is
167 (print 'true) 167 (print 'true)
168 'very-false) 168 'very-false)
169 @result{} very-false 169 @result{} very-false
170 @end group 170 @end group
171 @end example 171 @end example
172 @end defspec 172 @end deffn
173 173
174 @defspec cond clause@dots{} 174 @deffn {Special Operator} cond clause@dots{}
175 @code{cond} chooses among an arbitrary number of alternatives. Each 175 @code{cond} chooses among an arbitrary number of alternatives. Each
176 @var{clause} in the @code{cond} must be a list. The @sc{car} of this 176 @var{clause} in the @code{cond} must be a list. The @sc{car} of this
177 list is the @var{condition}; the remaining elements, if any, the 177 list is the @var{condition}; the remaining elements, if any, the
178 @var{body-forms}. Thus, a clause looks like this: 178 @var{body-forms}. Thus, a clause looks like this:
179 179
237 @end example 237 @end example
238 238
239 @noindent 239 @noindent
240 This expression is a @code{cond} which returns @code{foo} if the value 240 This expression is a @code{cond} which returns @code{foo} if the value
241 of @code{a} is 1, and returns the string @code{"default"} otherwise. 241 of @code{a} is 1, and returns the string @code{"default"} otherwise.
242 @end defspec 242 @end deffn
243 243
244 Any conditional construct can be expressed with @code{cond} or with 244 Any conditional construct can be expressed with @code{cond} or with
245 @code{if}. Therefore, the choice between them is a matter of style. 245 @code{if}. Therefore, the choice between them is a matter of style.
246 For example: 246 For example:
247 247
266 @code{t} if @var{condition} is @code{nil}, and @code{nil} otherwise. 266 @code{t} if @var{condition} is @code{nil}, and @code{nil} otherwise.
267 The function @code{not} is identical to @code{null}, and we recommend 267 The function @code{not} is identical to @code{null}, and we recommend
268 using the name @code{null} if you are testing for an empty list. 268 using the name @code{null} if you are testing for an empty list.
269 @end defun 269 @end defun
270 270
271 @defspec and conditions@dots{} 271 @deffn {Special Operator} and conditions@dots{}
272 The @code{and} special operator tests whether all the @var{conditions} are 272 The @code{and} special operator tests whether all the @var{conditions} are
273 true. It works by evaluating the @var{conditions} one by one in the 273 true. It works by evaluating the @var{conditions} one by one in the
274 order written. 274 order written.
275 275
276 If any of the @var{conditions} evaluates to @code{nil}, then the result 276 If any of the @var{conditions} evaluates to @code{nil}, then the result
318 (if @var{arg1} (if @var{arg2} @var{arg3})) 318 (if @var{arg1} (if @var{arg2} @var{arg3}))
319 @equiv{} 319 @equiv{}
320 (cond (@var{arg1} (cond (@var{arg2} @var{arg3})))) 320 (cond (@var{arg1} (cond (@var{arg2} @var{arg3}))))
321 @end group 321 @end group
322 @end example 322 @end example
323 @end defspec 323 @end deffn
324 324
325 @defspec or conditions@dots{} 325 @deffn {Special Operator} or conditions@dots{}
326 The @code{or} special operator tests whether at least one of the 326 The @code{or} special operator tests whether at least one of the
327 @var{conditions} is true. It works by evaluating all the 327 @var{conditions} is true. It works by evaluating all the
328 @var{conditions} one by one in the order written. 328 @var{conditions} one by one in the order written.
329 329
330 If any of the @var{conditions} evaluates to a non-@code{nil} value, then 330 If any of the @var{conditions} evaluates to a non-@code{nil} value, then
367 367
368 @noindent 368 @noindent
369 This is not completely equivalent because it can evaluate @var{arg1} or 369 This is not completely equivalent because it can evaluate @var{arg1} or
370 @var{arg2} twice. By contrast, @code{(or @var{arg1} @var{arg2} 370 @var{arg2} twice. By contrast, @code{(or @var{arg1} @var{arg2}
371 @var{arg3})} never evaluates any argument more than once. 371 @var{arg3})} never evaluates any argument more than once.
372 @end defspec 372 @end deffn
373 373
374 @node Iteration 374 @node Iteration
375 @section Iteration 375 @section Iteration
376 @cindex iteration 376 @cindex iteration
377 @cindex recursion 377 @cindex recursion
379 Iteration means executing part of a program repetitively. For 379 Iteration means executing part of a program repetitively. For
380 example, you might want to repeat some computation once for each element 380 example, you might want to repeat some computation once for each element
381 of a list, or once for each integer from 0 to @var{n}. You can do this 381 of a list, or once for each integer from 0 to @var{n}. You can do this
382 in XEmacs Lisp with the special operator @code{while}: 382 in XEmacs Lisp with the special operator @code{while}:
383 383
384 @defspec while condition forms@dots{} 384 @deffn {Special Operator} while condition forms@dots{}
385 @code{while} first evaluates @var{condition}. If the result is 385 @code{while} first evaluates @var{condition}. If the result is
386 non-@code{nil}, it evaluates @var{forms} in textual order. Then it 386 non-@code{nil}, it evaluates @var{forms} in textual order. Then it
387 reevaluates @var{condition}, and if the result is non-@code{nil}, it 387 reevaluates @var{condition}, and if the result is non-@code{nil}, it
388 evaluates @var{forms} again. This process repeats until @var{condition} 388 evaluates @var{forms} again. This process repeats until @var{condition}
389 evaluates to @code{nil}. 389 evaluates to @code{nil}.
425 425
426 @noindent 426 @noindent
427 This moves forward one line and continues moving by lines until it 427 This moves forward one line and continues moving by lines until it
428 reaches an empty. It is unusual in that the @code{while} has no body, 428 reaches an empty. It is unusual in that the @code{while} has no body,
429 just the end test (which also does the real work of moving point). 429 just the end test (which also does the real work of moving point).
430 @end defspec 430 @end deffn
431 431
432 @node Nonlocal Exits 432 @node Nonlocal Exits
433 @section Nonlocal Exits 433 @section Nonlocal Exits
434 @cindex nonlocal exits 434 @cindex nonlocal exits
435 435
497 chronologically after entry to the @code{catch}, and chronologically 497 chronologically after entry to the @code{catch}, and chronologically
498 before exit from it, it has access to that @code{catch}. This is why 498 before exit from it, it has access to that @code{catch}. This is why
499 @code{throw} can be used in commands such as @code{exit-recursive-edit} 499 @code{throw} can be used in commands such as @code{exit-recursive-edit}
500 that throw back to the editor command loop (@pxref{Recursive Editing}). 500 that throw back to the editor command loop (@pxref{Recursive Editing}).
501 501
502 @cindex CL note---only @code{throw} in Emacs 502 @deffn {Special Operator} catch tag body@dots{}
503 @quotation
504 @b{Common Lisp note:} Most other versions of Lisp, including Common Lisp,
505 have several ways of transferring control nonsequentially: @code{return},
506 @code{return-from}, and @code{go}, for example. XEmacs Lisp has only
507 @code{throw}.
508 @end quotation
509
510 @defspec catch tag body@dots{}
511 @cindex tag on run time stack 503 @cindex tag on run time stack
512 @code{catch} establishes a return point for the @code{throw} function. The 504 @code{catch} establishes a return point for the @code{throw} function. The
513 return point is distinguished from other such return points by @var{tag}, 505 return point is distinguished from other such return points by @var{tag},
514 which may be any Lisp object. The argument @var{tag} is evaluated normally 506 which may be any Lisp object. The argument @var{tag} is evaluated normally
515 before the return point is established. 507 before the return point is established.
520 the @code{catch}. 512 the @code{catch}.
521 513
522 If a @code{throw} is done within @var{body} specifying the same value 514 If a @code{throw} is done within @var{body} specifying the same value
523 @var{tag}, the @code{catch} exits immediately; the value it returns is 515 @var{tag}, the @code{catch} exits immediately; the value it returns is
524 whatever was specified as the second argument of @code{throw}. 516 whatever was specified as the second argument of @code{throw}.
525 @end defspec 517 @end deffn
526 518
527 @defun throw tag value 519 @defun throw tag value
528 The purpose of @code{throw} is to return from a return point previously 520 The purpose of @code{throw} is to return from a return point previously
529 established with @code{catch}. The argument @var{tag} is used to choose 521 established with @code{catch}. The argument @var{tag} is used to choose
530 among the various existing return points; it must be @code{eq} to the value 522 among the various existing return points; it must be @code{eq} to the value
1026 @code{catch}, but they are entirely separate facilities. An error 1018 @code{catch}, but they are entirely separate facilities. An error
1027 cannot be caught by a @code{catch}, and a @code{throw} cannot be handled 1019 cannot be caught by a @code{catch}, and a @code{throw} cannot be handled
1028 by an error handler (though using @code{throw} when there is no suitable 1020 by an error handler (though using @code{throw} when there is no suitable
1029 @code{catch} signals an error that can be handled). 1021 @code{catch} signals an error that can be handled).
1030 1022
1031 @defspec condition-case var protected-form handlers@dots{} 1023 @deffn {Special Operator} condition-case var protected-form handlers@dots{}
1032 This special operator establishes the error handlers @var{handlers} around 1024 This special operator establishes the error handlers @var{handlers} around
1033 the execution of @var{protected-form}. If @var{protected-form} executes 1025 the execution of @var{protected-form}. If @var{protected-form} executes
1034 without error, the value it returns becomes the value of the 1026 without error, the value it returns becomes the value of the
1035 @code{condition-case} form; in this case, the @code{condition-case} has 1027 @code{condition-case} form; in this case, the @code{condition-case} has
1036 no effect. The @code{condition-case} form makes a difference when an 1028 no effect. The @code{condition-case} form makes a difference when an
1075 the file name is the second element of @var{data}---the third element of 1067 the file name is the second element of @var{data}---the third element of
1076 @var{var}. 1068 @var{var}.
1077 1069
1078 If @var{var} is @code{nil}, that means no variable is bound. Then the 1070 If @var{var} is @code{nil}, that means no variable is bound. Then the
1079 error symbol and associated data are not available to the handler. 1071 error symbol and associated data are not available to the handler.
1080 @end defspec 1072 @end deffn
1081 1073
1082 @cindex @code{arith-error} example 1074 @cindex @code{arith-error} example
1083 Here is an example of using @code{condition-case} to handle the error 1075 Here is an example of using @code{condition-case} to handle the error
1084 that results from dividing by zero. The handler prints out a warning 1076 that results from dividing by zero. The handler prints out a warning
1085 message and returns a very large number. 1077 message and returns a very large number.
1250 1242
1251 The @code{unwind-protect} construct is essential whenever you 1243 The @code{unwind-protect} construct is essential whenever you
1252 temporarily put a data structure in an inconsistent state; it permits 1244 temporarily put a data structure in an inconsistent state; it permits
1253 you to ensure the data are consistent in the event of an error or throw. 1245 you to ensure the data are consistent in the event of an error or throw.
1254 1246
1255 @defspec unwind-protect body cleanup-forms@dots{} 1247 @deffn {Special Operator} unwind-protect body cleanup-forms@dots{}
1256 @cindex cleanup forms 1248 @cindex cleanup forms
1257 @cindex protected forms 1249 @cindex protected forms
1258 @cindex error cleanup 1250 @cindex error cleanup
1259 @cindex unwinding 1251 @cindex unwinding
1260 @code{unwind-protect} executes the @var{body} with a guarantee that the 1252 @code{unwind-protect} executes the @var{body} with a guarantee that the
1276 with another @code{unwind-protect} around that form. 1268 with another @code{unwind-protect} around that form.
1277 1269
1278 The number of currently active @code{unwind-protect} forms counts, 1270 The number of currently active @code{unwind-protect} forms counts,
1279 together with the number of local variable bindings, against the limit 1271 together with the number of local variable bindings, against the limit
1280 @code{max-specpdl-size} (@pxref{Local Variables}). 1272 @code{max-specpdl-size} (@pxref{Local Variables}).
1281 @end defspec 1273 @end deffn
1282 1274
1283 For example, here we make an invisible buffer for temporary use, and 1275 For example, here we make an invisible buffer for temporary use, and
1284 make sure to kill it before finishing: 1276 make sure to kill it before finishing:
1285 1277
1286 @smallexample 1278 @smallexample