diff options
| author | Michael Heerdegen | 2018-02-21 11:15:37 +0100 |
|---|---|---|
| committer | Michael Heerdegen | 2018-03-06 15:47:05 +0100 |
| commit | af4697faa1f5b643f63a9ea61aa205a4c1432e23 (patch) | |
| tree | 3b0e3e687d9bbcce246fc938fbd80bb398061ed9 /lisp | |
| parent | ec79bdc53fd75ea48c1451b0d83b0b41a0345bc6 (diff) | |
| download | emacs-af4697faa1f5b643f63a9ea61aa205a4c1432e23.tar.gz 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')
| -rw-r--r-- | lisp/emacs-lisp/subr-x.el | 55 |
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." | |||
| 121 | binding)) | 121 | binding)) |
| 122 | bindings))) | 122 | bindings))) |
| 123 | 123 | ||
| 124 | (defmacro if-let* (varlist then &rest else) | 124 | (defmacro if-let (varlist then &rest else) |
| 125 | "Bind variables according to VARLIST and eval THEN or ELSE. | 125 | "Bind variables according to VARLIST and eval THEN or ELSE. |
| 126 | Each binding is evaluated in turn, and evaluation stops if a | 126 | Each binding is evaluated in turn, and evaluation stops if a |
| 127 | binding value is nil. If all are non-nil, the value of THEN is | 127 | 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 | |||
| 131 | SYMBOL to the value of VALUEFORM. An element can additionally | 131 | SYMBOL to the value of VALUEFORM. An element can additionally |
| 132 | be of the form (VALUEFORM), which is evaluated and checked for | 132 | be of the form (VALUEFORM), which is evaluated and checked for |
| 133 | nil; i.e. SYMBOL can be omitted if only the test result is of | 133 | nil; i.e. SYMBOL can be omitted if only the test result is of |
| 134 | interest." | 134 | interest. |
| 135 | |||
| 136 | As a special case, a VARLIST of the form (SYMBOL SOMETHING) is | ||
| 137 | treated like ((SYMBOL SOMETHING))." | ||
| 135 | (declare (indent 2) | 138 | (declare (indent 2) |
| 136 | (debug ((&rest [&or symbolp (symbolp form) (form)]) | 139 | (debug ([&or (symbolp form) |
| 140 | (&rest [&or symbolp (symbolp form) (form)])] | ||
| 137 | form body))) | 141 | form body))) |
| 142 | (pcase varlist | ||
| 143 | (`(,(pred symbolp) ,_) | ||
| 144 | ;; the single-tuple syntax case, for backward compatibility | ||
| 145 | (cl-callf list varlist))) | ||
| 138 | (if varlist | 146 | (if varlist |
| 139 | `(let* ,(setq varlist (internal--build-bindings varlist)) | 147 | `(let* ,(setq varlist (internal--build-bindings varlist)) |
| 140 | (if ,(caar (last varlist)) | 148 | (if ,(caar (last varlist)) |
| @@ -142,23 +150,23 @@ interest." | |||
| 142 | ,@else)) | 150 | ,@else)) |
| 143 | `(let* () ,then))) | 151 | `(let* () ,then))) |
| 144 | 152 | ||
| 145 | (defmacro when-let* (varlist &rest body) | 153 | (defmacro when-let (varlist &rest body) |
| 146 | "Bind variables according to VARLIST and conditionally eval BODY. | 154 | "Bind variables according to VARLIST and conditionally eval BODY. |
| 147 | Each binding is evaluated in turn, and evaluation stops if a | 155 | Each binding is evaluated in turn, and evaluation stops if a |
| 148 | binding value is nil. If all are non-nil, the value of the last | 156 | binding value is nil. If all are non-nil, the value of the last |
| 149 | form in BODY is returned. | 157 | form in BODY is returned. |
| 150 | 158 | ||
| 151 | VARLIST is the same as in `if-let*'." | 159 | VARLIST is the same as in `if-let'." |
| 152 | (declare (indent 1) (debug if-let*)) | 160 | (declare (indent 1) (debug ([&or (symbolp form) |
| 153 | (list 'if-let* varlist (macroexp-progn body))) | 161 | (&rest [&or symbolp (symbolp form) (form)])] |
| 162 | body))) | ||
| 163 | (list 'if-let varlist (macroexp-progn body))) | ||
| 154 | 164 | ||
| 155 | (defmacro and-let* (varlist &rest body) | 165 | (defmacro and-let (varlist &rest body) |
| 156 | "Bind variables according to VARLIST and conditionally eval BODY. | 166 | "Bind variables according to VARLIST and conditionally eval BODY. |
| 157 | Like `when-let*', except if BODY is empty and all the bindings | 167 | Like `when-let', except if BODY is empty and all the bindings |
| 158 | are non-nil, then the result is non-nil." | 168 | are non-nil, then the result is non-nil." |
| 159 | (declare (indent 1) | 169 | (declare (indent 1) (debug when-let)) |
| 160 | (debug ((&rest [&or symbolp (symbolp form) (form)]) | ||
| 161 | body))) | ||
| 162 | (let (res) | 170 | (let (res) |
| 163 | (if varlist | 171 | (if varlist |
| 164 | `(let* ,(setq varlist (internal--build-bindings varlist)) | 172 | `(let* ,(setq varlist (internal--build-bindings varlist)) |
| @@ -166,26 +174,9 @@ are non-nil, then the result is non-nil." | |||
| 166 | ,@(or body `(,res)))) | 174 | ,@(or body `(,res)))) |
| 167 | `(let* () ,@(or body '(t)))))) | 175 | `(let* () ,@(or body '(t)))))) |
| 168 | 176 | ||
| 169 | (defmacro if-let (spec then &rest else) | 177 | (defalias 'if-let* #'if-let) |
| 170 | "Bind variables according to SPEC and eval THEN or ELSE. | 178 | (defalias 'when-let* #'when-let) |
| 171 | Like `if-let*' except SPEC can have the form (SYMBOL VALUEFORM)." | 179 | (defalias 'and-let* #'and-let) |
| 172 | (declare (indent 2) | ||
| 173 | (debug ([&or (&rest [&or symbolp (symbolp form) (form)]) | ||
| 174 | (symbolp form)] | ||
| 175 | form body)) | ||
| 176 | (obsolete "use `if-let*' instead." "26.1")) | ||
| 177 | (when (and (<= (length spec) 2) | ||
| 178 | (not (listp (car spec)))) | ||
| 179 | ;; Adjust the single binding case | ||
| 180 | (setq spec (list spec))) | ||
| 181 | (list 'if-let* spec then (macroexp-progn else))) | ||
| 182 | |||
| 183 | (defmacro when-let (spec &rest body) | ||
| 184 | "Bind variables according to SPEC and conditionally eval BODY. | ||
| 185 | Like `when-let*' except SPEC can have the form (SYMBOL VALUEFORM)." | ||
| 186 | (declare (indent 1) (debug if-let) | ||
| 187 | (obsolete "use `when-let*' instead." "26.1")) | ||
| 188 | (list 'if-let spec (macroexp-progn body))) | ||
| 189 | 180 | ||
| 190 | (defsubst hash-table-empty-p (hash-table) | 181 | (defsubst hash-table-empty-p (hash-table) |
| 191 | "Check whether HASH-TABLE is empty (has 0 elements)." | 182 | "Check whether HASH-TABLE is empty (has 0 elements)." |