Document and-let* vs. when-let* usage convention
authorSean Whitton <spwhitton@spwhitton.name>
Wed, 23 Oct 2024 01:07:06 +0000 (09:07 +0800)
committerSean Whitton <spwhitton@spwhitton.name>
Wed, 23 Oct 2024 01:08:27 +0000 (09:08 +0800)
* lisp/subr.el (and-let*): Document and/and-let*
vs. when/when-let* usage convention (some discussion in
bug#73853).
(when-let*): Add cross-reference to and-let*.

lisp/subr.el

index 28ba30f584e7754fc41dec7286dfcef1065a672e..d1b2a1efe6e9da6840babdbee4dad661ca15a7e0 100644 (file)
@@ -2640,14 +2640,22 @@ This is like `if-let' but doesn't handle a VARLIST of the form
 (defmacro when-let* (varlist &rest body)
   "Bind variables according to VARLIST and conditionally evaluate BODY.
 This is like `when-let' but doesn't handle a VARLIST of the form
-\(SYMBOL SOMETHING) specially."
+\(SYMBOL SOMETHING) specially.
+
+See also `and-let*'."
   (declare (indent 1) (debug if-let*))
   (list 'if-let* varlist (macroexp-progn body)))
 
 (defmacro and-let* (varlist &rest body)
   "Bind variables according to VARLIST and conditionally evaluate BODY.
 Like `when-let*', except if BODY is empty and all the bindings
-are non-nil, then the result is the value of the last binding."
+are non-nil, then the result is the value of the last binding.
+
+Some Lisp programmers follow the convention that `and' and `and-let*'
+are for forms evaluated for return value, and `when' and `when-let*' are
+for forms evaluated for side-effect with returned values ignored."
+  ;; Document this convention here because it partially explains why we
+  ;; have both `when-let*' and `and-let*'.
   (declare (indent 1) (debug if-let*))
   (let (res)
     (if varlist