aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorJoost Kremers2024-11-11 23:38:49 +0100
committerSean Whitton2024-11-25 12:45:00 +0800
commit3e396b2c5bb8abdc16218ca8c9d617b9dcf9f01e (patch)
tree346243de7f5389681f90df4f1ffdab1486801c7c /doc
parent50b91ed458df8f04359996b31b18fb318ba64a47 (diff)
downloademacs-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.texi64
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
322described below. 322described below.
323 323
324@defmac if-let* varlist then-form else-forms... 324@defmac if-let* varlist then-form else-forms...
325Evaluate each binding in @var{varlist} in turn, like in @code{let*} 325Evaluate 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
327If all are non-@code{nil}, return the value of @var{then-form}, 327@var{then-form}, otherwise the last form in @var{else-forms}.
328otherwise the last form in @var{else-forms}. 328
329Each element of @code{varlist} has the form @w{@code{(@var{symbol}
330@var{value-form})}}: @var{value-form} is evaluated and @var{symbol} is
331locally bound to the result. Bindings are sequential, as in @code{let*}
332(@pxref{Local Variables}). As a special case, @var{symbol} can be
333omitted 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
335is not bound.
329@end defmac 336@end defmac
330 337
331@defmac when-let* varlist then-forms... 338@defmac when-let* varlist then-forms...
332Like @code{if-let*}, but without @var{else-forms}. 339Evaluate 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
341form 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})}},
345in which @var{value-form} is evaluated and @var{symbol} is locally bound
346to the result. Bindings are sequential, as in @code{let*} (@pxref{Local
347Variables}). As a special case, @var{symbol} can be omitted if only the
348test result of @var{value-form} is of interest: @var{value-form} is
349evaluated 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...
336Like @code{when-let*}, but in addition, if there are no 353Evaluate 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
355form in @var{then-forms}, or, if there are no @var{then-forms}, return
338the value of the last binding. 356the 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
342Like @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}. 360in which @var{value-form} is evaluated and @var{symbol} is locally bound
361to the result. Bindings are sequential, as in @code{let*} (@pxref{Local
362Variables}). As a special case, @var{symbol} can be omitted if only the
363test result of @var{value-form} is of interest: @var{value-form} is
364evaluated and checked for @code{nil}, but its value is not bound.
344@end defmac 365@end defmac
345 366
346Some Lisp programmers follow the convention that @code{and} and 367Some 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
349with returned values ignored. 370with returned values ignored.
350 371
372A similar macro exists to run a loop until one binding evaluates to
373@code{nil}:
374
375@defmac while-let spec then-forms...
376Evaluate each binding in @var{spec} in turn, stopping if a binding value
377is @code{nil}. If all are non-@code{nil}, execute @var{then-forms},
378then 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
380established 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})}},
384in which @var{value-form} is evaluated and @var{symbol} is locally bound
385to the result. Bindings are sequential, as in @code{let*} (@pxref{Local
386Variables}). As a special case, @var{symbol} can be omitted if only the
387test result of @var{value-form} is of interest: @var{value-form} is
388evaluated and checked for @code{nil}, but its value is not bound.
389
390The 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