diff options
| author | Sean Whitton | 2025-10-07 17:31:34 +0100 |
|---|---|---|
| committer | Sean Whitton | 2025-10-07 17:35:06 +0100 |
| commit | da47fa2f23bde6cc96f90f56ccf383128affb748 (patch) | |
| tree | a93364fe60ebd2bae74ead9f0a6aab0ef77b23ce | |
| parent | db7fd704deee3cbb7d7af72126c992cbc55383f9 (diff) | |
| download | emacs-da47fa2f23bde6cc96f90f56ccf383128affb748.tar.gz emacs-da47fa2f23bde6cc96f90f56ccf383128affb748.zip | |
if-let*/when-let*/and-let*: Don't recommend (VALUEFORM) form
* doc/lispref/control.texi (Conditionals):
* lisp/subr.el (if-let*): Document '(_ VALUEFORM)' instead of
'(VALUEFORM)'.
| -rw-r--r-- | doc/lispref/control.texi | 21 | ||||
| -rw-r--r-- | lisp/subr.el | 21 |
2 files changed, 25 insertions, 17 deletions
diff --git a/doc/lispref/control.texi b/doc/lispref/control.texi index 689e7324d43..8f1f144e765 100644 --- a/doc/lispref/control.texi +++ b/doc/lispref/control.texi | |||
| @@ -317,7 +317,7 @@ following way instead: | |||
| 317 | (do-something result2)) | 317 | (do-something result2)) |
| 318 | @end example | 318 | @end example |
| 319 | 319 | ||
| 320 | There's a number of variations on this theme, and they're briefly | 320 | There are a number of variations on this theme, and they're briefly |
| 321 | described below. | 321 | described below. |
| 322 | 322 | ||
| 323 | @defmac if-let* varlist then-form else-forms... | 323 | @defmac if-let* varlist then-form else-forms... |
| @@ -328,10 +328,9 @@ Evaluate each binding in @var{varlist}, stopping if a binding value is | |||
| 328 | Each element of @code{varlist} has the form @w{@code{(@var{symbol} | 328 | Each element of @code{varlist} has the form @w{@code{(@var{symbol} |
| 329 | @var{value-form})}}: @var{value-form} is evaluated and @var{symbol} is | 329 | @var{value-form})}}: @var{value-form} is evaluated and @var{symbol} is |
| 330 | locally bound to the result. Bindings are sequential, as in @code{let*} | 330 | locally bound to the result. Bindings are sequential, as in @code{let*} |
| 331 | (@pxref{Local Variables}). As a special case, @var{symbol} can be | 331 | (@pxref{Local Variables}). If only the test result of @var{value-form} |
| 332 | omitted if only the test result of @var{value-form} is of interest: | 332 | is of interest, use @code{_} for @var{symbol}. Then @var{value-form} is |
| 333 | @var{value-form} is evaluated and checked for @code{nil}, but its value | 333 | evaluated and checked for @code{nil}, but its value is not bound. |
| 334 | is not bound. | ||
| 335 | @end defmac | 334 | @end defmac |
| 336 | 335 | ||
| 337 | @defmac when-let* varlist then-forms... | 336 | @defmac when-let* varlist then-forms... |
| @@ -343,8 +342,8 @@ form in @var{then-forms}. | |||
| 343 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, | 342 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, |
| 344 | in which @var{value-form} is evaluated and @var{symbol} is locally bound | 343 | in which @var{value-form} is evaluated and @var{symbol} is locally bound |
| 345 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local | 344 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local |
| 346 | Variables}). As a special case, @var{symbol} can be omitted if only the | 345 | Variables}). If only the test result of @var{value-form} |
| 347 | test result of @var{value-form} is of interest: @var{value-form} is | 346 | is of interest, use @code{_} for @var{symbol}. Then @var{value-form} is |
| 348 | evaluated and checked for @code{nil}, but its value is not bound. | 347 | evaluated and checked for @code{nil}, but its value is not bound. |
| 349 | @end defmac | 348 | @end defmac |
| 350 | 349 | ||
| @@ -358,8 +357,8 @@ the value of the last binding. | |||
| 358 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, | 357 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, |
| 359 | in which @var{value-form} is evaluated and @var{symbol} is locally bound | 358 | in which @var{value-form} is evaluated and @var{symbol} is locally bound |
| 360 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local | 359 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local |
| 361 | Variables}). As a special case, @var{symbol} can be omitted if only the | 360 | Variables}). If only the test result of @var{value-form} is of |
| 362 | test result of @var{value-form} is of interest: @var{value-form} is | 361 | interest, use @code{_} for @var{symbol}. Then @var{value-form} is |
| 363 | evaluated and checked for @code{nil}, but its value is not bound. | 362 | evaluated and checked for @code{nil}, but its value is not bound. |
| 364 | @end defmac | 363 | @end defmac |
| 365 | 364 | ||
| @@ -382,8 +381,8 @@ established anew. | |||
| 382 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, | 381 | @code{varlist} has the form @w{@code{(@var{symbol} @var{value-form})}}, |
| 383 | in which @var{value-form} is evaluated and @var{symbol} is locally bound | 382 | in which @var{value-form} is evaluated and @var{symbol} is locally bound |
| 384 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local | 383 | to the result. Bindings are sequential, as in @code{let*} (@pxref{Local |
| 385 | Variables}). As a special case, @var{symbol} can be omitted if only the | 384 | Variables}). If only the test result of @var{value-form} is of |
| 386 | test result of @var{value-form} is of interest: @var{value-form} is | 385 | interest, use @code{_} for @var{symbol}. Then @var{value-form} is |
| 387 | evaluated and checked for @code{nil}, but its value is not bound. | 386 | evaluated and checked for @code{nil}, but its value is not bound. |
| 388 | 387 | ||
| 389 | The return value of @code{while-let} is always @code{nil}. | 388 | The return value of @code{while-let} is always @code{nil}. |
diff --git a/lisp/subr.el b/lisp/subr.el index 50ebc598e80..7bd436d898a 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -2632,6 +2632,9 @@ Affects only hooks run in the current buffer." | |||
| 2632 | binding)) | 2632 | binding)) |
| 2633 | bindings))) | 2633 | bindings))) |
| 2634 | 2634 | ||
| 2635 | ;; FIXME: Once Emacs 29 is ancient history we can consider a | ||
| 2636 | ;; byte-compiler warning. This is because Emacs 29 and older will warn | ||
| 2637 | ;; about unused variables with (_ VALUEFORM). | ||
| 2635 | (defmacro if-let* (varlist then &rest else) | 2638 | (defmacro if-let* (varlist then &rest else) |
| 2636 | "Bind variables according to VARLIST and evaluate THEN or ELSE. | 2639 | "Bind variables according to VARLIST and evaluate THEN or ELSE. |
| 2637 | Evaluate each binding in turn, as in `let*', stopping if a | 2640 | Evaluate each binding in turn, as in `let*', stopping if a |
| @@ -2639,12 +2642,18 @@ binding value is nil. If all are non-nil return the value of | |||
| 2639 | THEN, otherwise the value of the last form in ELSE, or nil if | 2642 | THEN, otherwise the value of the last form in ELSE, or nil if |
| 2640 | there are none. | 2643 | there are none. |
| 2641 | 2644 | ||
| 2642 | Each element of VARLIST is a list (SYMBOL VALUEFORM) that binds | 2645 | Each element of VARLIST is a list (SYMBOL VALUEFORM) that binds SYMBOL |
| 2643 | SYMBOL to the value of VALUEFORM. An element can additionally be | 2646 | to the value of VALUEFORM. If only the test result is of interest, use |
| 2644 | of the form (VALUEFORM), which is evaluated and checked for nil; | 2647 | `_' as SYMBOL, i.e. (_ VALUEFORM), in which case VALUEFORM is evaluated |
| 2645 | i.e. SYMBOL can be omitted if only the test result is of | 2648 | and checked for nil but the result is not bound. |
| 2646 | interest. It can also be of the form SYMBOL, then the binding of | 2649 | An element of VARLIST can also be of the form SYMBOL, in which case the |
| 2647 | SYMBOL is checked for nil." | 2650 | binding of SYMBOL is checked for nil, only. |
| 2651 | |||
| 2652 | An older form for entries of VARLIST is also supported, where SYMBOL is | ||
| 2653 | omitted, i.e. (VALUEFORM). This means the same as (_ VALUEFORM). | ||
| 2654 | This form is not recommended because many programmers find it | ||
| 2655 | significantly less readable. A future release of Emacs may introduce a | ||
| 2656 | byte-compiler warning for uses of (VALUEFORM) in VARLIST." | ||
| 2648 | (declare (indent 2) | 2657 | (declare (indent 2) |
| 2649 | (debug ((&rest [&or symbolp (symbolp form) (form)]) | 2658 | (debug ((&rest [&or symbolp (symbolp form) (form)]) |
| 2650 | body))) | 2659 | body))) |