Function: if-let*
if-let* is a macro defined in subr.el.gz.
Signature
(if-let* VARLIST THEN &rest ELSE)
Documentation
Bind variables according to VARLIST and evaluate THEN or ELSE.
Evaluate each binding in turn, as in let*, stopping if a
binding value is nil. If all are non-nil return the value of
THEN, otherwise the value of the last form in ELSE, or nil if
there are none.
Each element of VARLIST is a list (SYMBOL VALUEFORM) that binds SYMBOL
to the value of VALUEFORM. If only the test result is of interest, use
_ as SYMBOL, i.e. (_ VALUEFORM), in which case VALUEFORM is evaluated
and checked for nil but the result is not bound.
An element of VARLIST can also be of the form SYMBOL, in which case the
binding of SYMBOL is checked for nil, only.
An older form for entries of VARLIST is also supported, where SYMBOL is omitted, i.e. (VALUEFORM). This means the same as (_ VALUEFORM). This form is not recommended because many Lisp programmers find it significantly less readable. A future release of Emacs may introduce a byte-compiler warning for uses of (VALUEFORM) in VARLIST.
Probably introduced at or before Emacs version 31.1.
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
;; FIXME: Once Emacs 29 is ancient history we can consider a
;; byte-compiler warning. This is because Emacs 29 and older will warn
;; about unused variables with (_ VALUEFORM).
(defmacro if-let* (varlist then &rest else)
"Bind variables according to VARLIST and evaluate THEN or ELSE.
Evaluate each binding in turn, as in `let*', stopping if a
binding value is nil. If all are non-nil return the value of
THEN, otherwise the value of the last form in ELSE, or nil if
there are none.
Each element of VARLIST is a list (SYMBOL VALUEFORM) that binds SYMBOL
to the value of VALUEFORM. If only the test result is of interest, use
`_' as SYMBOL, i.e. (_ VALUEFORM), in which case VALUEFORM is evaluated
and checked for nil but the result is not bound.
An element of VARLIST can also be of the form SYMBOL, in which case the
binding of SYMBOL is checked for nil, only.
An older form for entries of VARLIST is also supported, where SYMBOL is
omitted, i.e. (VALUEFORM). This means the same as (_ VALUEFORM).
This form is not recommended because many Lisp programmers find it
significantly less readable. A future release of Emacs may introduce a
byte-compiler warning for uses of (VALUEFORM) in VARLIST."
(declare (indent 2)
(debug ((&rest [&or symbolp (symbolp form) (form)])
body)))
(if varlist
`(let* ,(setq varlist (internal--build-bindings varlist))
(if ,(caar (last varlist))
,then
,@else))
`(let* () ,then)))