Mercurial > emacs
comparison lispref/control.texi @ 60037:45e78cd94f23
(Combining Conditions): Wording cleanup.
(Iteration): dolist and dotimes bind VAR locally.
(Cleanups): Xref to Atomic Changes.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 14 Feb 2005 10:07:43 +0000 |
parents | c9aa4127a482 |
children | 75c04f750f89 7e3f621f1dd4 |
comparison
equal
deleted
inserted
replaced
60036:fafa7c0e2b82 | 60037:45e78cd94f23 |
---|---|
344 | 344 |
345 @noindent | 345 @noindent |
346 Note that @code{(car foo)} is not executed if @code{(consp foo)} returns | 346 Note that @code{(car foo)} is not executed if @code{(consp foo)} returns |
347 @code{nil}, thus avoiding an error. | 347 @code{nil}, thus avoiding an error. |
348 | 348 |
349 @code{and} can be expressed in terms of either @code{if} or @code{cond}. | 349 @code{and} expressions can also be written using either @code{if} or |
350 For example: | 350 @code{cond}. Here's how: |
351 | 351 |
352 @example | 352 @example |
353 @group | 353 @group |
354 (and @var{arg1} @var{arg2} @var{arg3}) | 354 (and @var{arg1} @var{arg2} @var{arg3}) |
355 @equiv{} | 355 @equiv{} |
474 The @code{dolist} and @code{dotimes} macros provide convenient ways to | 474 The @code{dolist} and @code{dotimes} macros provide convenient ways to |
475 write two common kinds of loops. | 475 write two common kinds of loops. |
476 | 476 |
477 @defmac dolist (var list [result]) body@dots{} | 477 @defmac dolist (var list [result]) body@dots{} |
478 @tindex dolist | 478 @tindex dolist |
479 This construct executes @var{body} once for each element of @var{list}, | 479 This construct executes @var{body} once for each element of |
480 using the variable @var{var} to hold the current element. Then it | 480 @var{list}, binding the variable @var{var} locally to hold the current |
481 returns the value of evaluating @var{result}, or @code{nil} if | 481 element. Then it returns the value of evaluating @var{result}, or |
482 @var{result} is omitted. For example, here is how you could use | 482 @code{nil} if @var{result} is omitted. For example, here is how you |
483 @code{dolist} to define the @code{reverse} function: | 483 could use @code{dolist} to define the @code{reverse} function: |
484 | 484 |
485 @example | 485 @example |
486 (defun reverse (list) | 486 (defun reverse (list) |
487 (let (value) | 487 (let (value) |
488 (dolist (elt list value) | 488 (dolist (elt list value) |
491 @end defmac | 491 @end defmac |
492 | 492 |
493 @defmac dotimes (var count [result]) body@dots{} | 493 @defmac dotimes (var count [result]) body@dots{} |
494 @tindex dotimes | 494 @tindex dotimes |
495 This construct executes @var{body} once for each integer from 0 | 495 This construct executes @var{body} once for each integer from 0 |
496 (inclusive) to @var{count} (exclusive), using the variable @var{var} to | 496 (inclusive) to @var{count} (exclusive), binding the variable @var{var} |
497 hold the integer for the current iteration. Then it returns the value | 497 to the integer for the current iteration. Then it returns the value |
498 of evaluating @var{result}, or @code{nil} if @var{result} is omitted. | 498 of evaluating @var{result}, or @code{nil} if @var{result} is omitted. |
499 Here is an example of using @code{dotimes} to do something 100 times: | 499 Here is an example of using @code{dotimes} to do something 100 times: |
500 | 500 |
501 @example | 501 @example |
502 (dotimes (i 100) | 502 (dotimes (i 100) |
1165 @node Cleanups | 1165 @node Cleanups |
1166 @subsection Cleaning Up from Nonlocal Exits | 1166 @subsection Cleaning Up from Nonlocal Exits |
1167 | 1167 |
1168 The @code{unwind-protect} construct is essential whenever you | 1168 The @code{unwind-protect} construct is essential whenever you |
1169 temporarily put a data structure in an inconsistent state; it permits | 1169 temporarily put a data structure in an inconsistent state; it permits |
1170 you to make the data consistent again in the event of an error or throw. | 1170 you to make the data consistent again in the event of an error or |
1171 throw. (Another more specific cleanup construct that is used only for | |
1172 changes in buffer contents is the atomic change group; @ref{Atomic | |
1173 Changes}.) | |
1171 | 1174 |
1172 @defspec unwind-protect body-form cleanup-forms@dots{} | 1175 @defspec unwind-protect body-form cleanup-forms@dots{} |
1173 @cindex cleanup forms | 1176 @cindex cleanup forms |
1174 @cindex protected forms | 1177 @cindex protected forms |
1175 @cindex error cleanup | 1178 @cindex error cleanup |