summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorMichael Heerdegen <michael_heerdegen@web.de>2018-02-21 11:15:37 +0100
committerMichael Heerdegen <michael_heerdegen@web.de>2018-03-06 15:47:05 +0100
commitaf4697faa1f5b643f63a9ea61aa205a4c1432e23 (patch)
tree3b0e3e687d9bbcce246fc938fbd80bb398061ed9 /lisp/emacs-lisp
parentec79bdc53fd75ea48c1451b0d83b0b41a0345bc6 (diff)
downloademacs-af4697faa1f5b643f63a9ea61aa205a4c1432e23.tar.gz
emacs-af4697faa1f5b643f63a9ea61aa205a4c1432e23.tar.bz2
emacs-af4697faa1f5b643f63a9ea61aa205a4c1432e23.zip
Define if-let* and derivatives as aliases for if-let etc
This commit reverts declaring `if-let' and `when-let' obsolete in favor of the new `if-let*' and `when-let*' versions because of the compiler warning mess (Bug#30039). Instead we make foo-let* aliases for foo-let. The old single-tuple variable spec case is still supported for backward compatibility. * lisp/emacs-lisp/subr-x.el (if-let, when-let): Don't declare obsolete. Tweak edebug specs. (and-let): Renamed from `and-let*' for compatibility with the names `if-let' and `when-let'. (if-let*, when-let*, and-let*): Define as aliases for `if-let', `when-let' and `and-let'. * test/lisp/emacs-lisp/subr-x-tests.el (if-let-single-tuple-case-test) (when-let-single-tuple-case-test): New tests for the single-binding tuple case. In the whole file, prefer the names without "*".
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/subr-x.el55
1 files changed, 23 insertions, 32 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 21dba377bf1..b2d7f0dec4f 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -121,7 +121,7 @@ If ELT is of the form ((EXPR)), listify (EXPR) with a dummy symbol."
binding))
bindings)))
-(defmacro if-let* (varlist then &rest else)
+(defmacro if-let (varlist then &rest else)
"Bind variables according to VARLIST and eval THEN or ELSE.
Each binding is evaluated in turn, and evaluation stops if a
binding value is nil. If all are non-nil, the value of THEN is
@@ -131,10 +131,18 @@ Each element of VARLIST is a list (SYMBOL VALUEFORM) which binds
SYMBOL to the value of VALUEFORM. An element can additionally
be of the form (VALUEFORM), which is evaluated and checked for
nil; i.e. SYMBOL can be omitted if only the test result is of
-interest."
+interest.
+
+As a special case, a VARLIST of the form (SYMBOL SOMETHING) is
+treated like ((SYMBOL SOMETHING))."
(declare (indent 2)
- (debug ((&rest [&or symbolp (symbolp form) (form)])
+ (debug ([&or (symbolp form)
+ (&rest [&or symbolp (symbolp form) (form)])]
form body)))
+ (pcase varlist
+ (`(,(pred symbolp) ,_)
+ ;; the single-tuple syntax case, for backward compatibility
+ (cl-callf list varlist)))
(if varlist
`(let* ,(setq varlist (internal--build-bindings varlist))
(if ,(caar (last varlist))
@@ -142,23 +150,23 @@ interest."
,@else))
`(let* () ,then)))
-(defmacro when-let* (varlist &rest body)
+(defmacro when-let (varlist &rest body)
"Bind variables according to VARLIST and conditionally eval BODY.
Each binding is evaluated in turn, and evaluation stops if a
binding value is nil. If all are non-nil, the value of the last
form in BODY is returned.
-VARLIST is the same as in `if-let*'."
- (declare (indent 1) (debug if-let*))
- (list 'if-let* varlist (macroexp-progn body)))
+VARLIST is the same as in `if-let'."
+ (declare (indent 1) (debug ([&or (symbolp form)
+ (&rest [&or symbolp (symbolp form) (form)])]
+ body)))
+ (list 'if-let varlist (macroexp-progn body)))
-(defmacro and-let* (varlist &rest body)
+(defmacro and-let (varlist &rest body)
"Bind variables according to VARLIST and conditionally eval BODY.
-Like `when-let*', except if BODY is empty and all the bindings
+Like `when-let', except if BODY is empty and all the bindings
are non-nil, then the result is non-nil."
- (declare (indent 1)
- (debug ((&rest [&or symbolp (symbolp form) (form)])
- body)))
+ (declare (indent 1) (debug when-let))
(let (res)
(if varlist
`(let* ,(setq varlist (internal--build-bindings varlist))
@@ -166,26 +174,9 @@ are non-nil, then the result is non-nil."
,@(or body `(,res))))
`(let* () ,@(or body '(t))))))
-(defmacro if-let (spec then &rest else)
- "Bind variables according to SPEC and eval THEN or ELSE.
-Like `if-let*' except SPEC can have the form (SYMBOL VALUEFORM)."
- (declare (indent 2)
- (debug ([&or (&rest [&or symbolp (symbolp form) (form)])
- (symbolp form)]
- form body))
- (obsolete "use `if-let*' instead." "26.1"))
- (when (and (<= (length spec) 2)
- (not (listp (car spec))))
- ;; Adjust the single binding case
- (setq spec (list spec)))
- (list 'if-let* spec then (macroexp-progn else)))
-
-(defmacro when-let (spec &rest body)
- "Bind variables according to SPEC and conditionally eval BODY.
-Like `when-let*' except SPEC can have the form (SYMBOL VALUEFORM)."
- (declare (indent 1) (debug if-let)
- (obsolete "use `when-let*' instead." "26.1"))
- (list 'if-let spec (macroexp-progn body)))
+(defalias 'if-let* #'if-let)
+(defalias 'when-let* #'when-let)
+(defalias 'and-let* #'and-let)
(defsubst hash-table-empty-p (hash-table)
"Check whether HASH-TABLE is empty (has 0 elements)."