mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-06-14 12:31:25 +00:00
; Suggest not using if-let* and friends to bind never-nil values.
This commit is contained in:
parent
d9611a7686
commit
1fb515e79f
1 changed files with 27 additions and 0 deletions
|
|
@ -376,6 +376,33 @@ Some Lisp programmers follow the convention that @code{and} and
|
|||
@code{when} and @code{when-let*} are for forms evaluated for side-effect
|
||||
with returned values ignored.
|
||||
|
||||
As a matter of style, it is best not to use these macros to bind values
|
||||
that will always be non-@code{nil}. For example, suppose that
|
||||
@code{foo-p} and @code{bar-p} might return @code{nil}, and the code
|
||||
should not proceed in that case. Instead of
|
||||
|
||||
@example
|
||||
(when-let* ((foo-val (foo-p))
|
||||
(num (+ 2 foo-val))
|
||||
(bar-val (bar-p)))
|
||||
...)
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
consider using
|
||||
|
||||
@example
|
||||
(when-let* ((foo-val (foo-p)))
|
||||
(let ((num (+ 2 foo-val))
|
||||
(when-let* ((bar-val (bar-p)))
|
||||
...)))
|
||||
@end example
|
||||
|
||||
@noindent
|
||||
because this makes it clearer that the execution of the code is
|
||||
conditional on @code{foo-val} and @code{bar-val} being non-@code{nil},
|
||||
but not directly conditional on @code{num}.
|
||||
|
||||
There is no @code{cond-let*} macro because extending the structure
|
||||
shared by @code{if-let*}, @code{when-let*} and @code{and-let*} to the
|
||||
case of @code{cond} is not simple.@footnote{The problem is that there
|
||||
|
|
|
|||
Loading…
Reference in a new issue