diff options
| author | Joost Kremers | 2024-11-11 23:38:49 +0100 |
|---|---|---|
| committer | Sean Whitton | 2024-11-25 12:45:00 +0800 |
| commit | 3e396b2c5bb8abdc16218ca8c9d617b9dcf9f01e (patch) | |
| tree | 346243de7f5389681f90df4f1ffdab1486801c7c /doc | |
| parent | 50b91ed458df8f04359996b31b18fb318ba64a47 (diff) | |
| download | emacs-3e396b2c5bb8abdc16218ca8c9d617b9dcf9f01e.tar.gz emacs-3e396b2c5bb8abdc16218ca8c9d617b9dcf9f01e.zip | |
Improve documentation for 'while-let'
* doc/lispref/control.texi (Conditionals): Reorganise describing
what's overlapping between the macros (and between the macros
and let*), and then improve the documentation for 'while-let'.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/control.texi | 64 |
1 files changed, 53 insertions, 11 deletions
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 41f40ea852c..17f91606a86 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi | |||
| @@ -322,25 +322,46 @@ There's a number of variations on this theme, and they're briefly | |||
| 322 | described below. | 322 | described below. |
| 323 | 323 | ||
| 324 | @defmac if-let* varlist then-form else-forms... | 324 | @defmac if-let* varlist then-form else-forms... |
| 325 | Evaluate each binding in @var{varlist} in turn, like in @code{let*} | 325 | Evaluate each binding in @var{varlist}, stopping if a binding value is |
| 326 | (@pxref{Local Variables}), stopping if a binding value is @code{nil}. | 326 | @code{nil}. If all are non-@code{nil}, return the value of |
| 327 | If all are non-@code{nil}, return the value of @var{then-form}, | 327 | @var{then-form}, otherwise the last form in @var{else-forms}. |
| 328 | otherwise the last form in @var{else-forms}. | 328 | |
| 329 | Each element of @code{varlist} has the form @w{@code{(@var{symbol} | ||
| 330 | @var{value-form})}}: @var{value-form} is evaluated and @var{symbol} is | ||
| 331 | locally bound to the result. Bindings are sequential, as in @code{let*} | ||
| 332 | (@pxref{Local Variables}). As a special case, @var{symbol} can be | ||
| 333 | omitted if only the test result of @var{value-form} is of interest: | ||
| 334 | @var{value-form} is evaluated and checked for @code{nil}, but its value | ||
| 335 | is not bound. | ||
| 329 | @end defmac | 336 | @end defmac |
| 330 | 337 | ||
| 331 | @defmac when-let* varlist then-forms... | 338 | @defmac when-let* varlist then-forms... |
| 332 | Like @code{if-let*}, but without @var{else-forms}. | 339 | Evaluate each binding in @var{varlist}, stopping if a binding value is |
| 340 | @code{nil}. If all are non-@code{nil}, return the value of the last | ||
| 341 | form in @var{then-forms}. | ||
| 342 | |||
| 343 | @var{varlist} has the same form as in @code{if-let*}: Each element of | ||
| 344 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, | ||
| 345 | in which @var{value-form} is evaluated and @var{symbol} is locally bound | ||
| 346 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local | ||
| 347 | Variables}). As a special case, @var{symbol} can be omitted if only the | ||
| 348 | test result of @var{value-form} is of interest: @var{value-form} is | ||
| 349 | evaluated and checked for @code{nil}, but its value is not bound. | ||
| 333 | @end defmac | 350 | @end defmac |
| 334 | 351 | ||
| 335 | @defmac and-let* varlist then-forms... | 352 | @defmac and-let* varlist then-forms... |
| 336 | Like @code{when-let*}, but in addition, if there are no | 353 | Evaluate each binding in @var{varlist}, stopping if a binding value is |
| 337 | @var{then-forms} and all the bindings evaluate to non-@code{nil}, return | 354 | @code{nil}. If all are non-@code{nil}, return the value of the last |
| 355 | form in @var{then-forms}, or, if there are no @var{then-forms}, return | ||
| 338 | the value of the last binding. | 356 | the value of the last binding. |
| 339 | @end defmac | ||
| 340 | 357 | ||
| 341 | @defmac while-let spec then-forms... | 358 | @var{varlist} has the same form as in @code{if-let*}: Each element of |
| 342 | Like @code{when-let*}, but repeat until a binding in @var{spec} is | 359 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, |
| 343 | @code{nil}. The return value is always @code{nil}. | 360 | in which @var{value-form} is evaluated and @var{symbol} is locally bound |
| 361 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local | ||
| 362 | Variables}). As a special case, @var{symbol} can be omitted if only the | ||
| 363 | test result of @var{value-form} is of interest: @var{value-form} is | ||
| 364 | evaluated and checked for @code{nil}, but its value is not bound. | ||
| 344 | @end defmac | 365 | @end defmac |
| 345 | 366 | ||
| 346 | Some Lisp programmers follow the convention that @code{and} and | 367 | Some Lisp programmers follow the convention that @code{and} and |
| @@ -348,6 +369,27 @@ Some Lisp programmers follow the convention that @code{and} and | |||
| 348 | @code{when} and @code{when-let*} are for forms evaluated for side-effect | 369 | @code{when} and @code{when-let*} are for forms evaluated for side-effect |
| 349 | with returned values ignored. | 370 | with returned values ignored. |
| 350 | 371 | ||
| 372 | A similar macro exists to run a loop until one binding evaluates to | ||
| 373 | @code{nil}: | ||
| 374 | |||
| 375 | @defmac while-let spec then-forms... | ||
| 376 | Evaluate each binding in @var{spec} in turn, stopping if a binding value | ||
| 377 | is @code{nil}. If all are non-@code{nil}, execute @var{then-forms}, | ||
| 378 | then repeat the loop. Note that when the loop is repeated, the | ||
| 379 | @var{value-forms} in @var{spec} are re-evaluated and the bindings are | ||
| 380 | established anew. | ||
| 381 | |||
| 382 | @var{varlist} has the same form as in @code{if-let*}: Each element of | ||
| 383 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, | ||
| 384 | in which @var{value-form} is evaluated and @var{symbol} is locally bound | ||
| 385 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local | ||
| 386 | Variables}). As a special case, @var{symbol} can be omitted if only the | ||
| 387 | test result of @var{value-form} is of interest: @var{value-form} is | ||
| 388 | evaluated and checked for @code{nil}, but its value is not bound. | ||
| 389 | |||
| 390 | The return value of @code{while-let} is always @code{nil}. | ||
| 391 | @end defmac | ||
| 392 | |||
| 351 | @node Combining Conditions | 393 | @node Combining Conditions |
| 352 | @section Constructs for Combining Conditions | 394 | @section Constructs for Combining Conditions |
| 353 | @cindex combining conditions | 395 | @cindex combining conditions |