aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Oteiza2017-02-03 21:42:42 -0500
committerMark Oteiza2017-02-03 21:42:42 -0500
commitbe10c00d3d64d53a7f31441d42f6c5b1f75b9916 (patch)
treef6398751a5f5d16e902f7d4b31e3912e550424f3
parente080d019f41d2738ba0db721c1b89ea57413439b (diff)
downloademacs-be10c00d3d64d53a7f31441d42f6c5b1f75b9916.tar.gz
emacs-be10c00d3d64d53a7f31441d42f6c5b1f75b9916.zip
Rename to if-let* and when-let*
Make the existing if-let and when-let aliases. * lisp/emacs-lisp/subr-x.el (if-let*, when-let*): New macros. Rewrite docstrings, incorporating that from let* and the existing if-let. (if-let, when-let, and-let*): Alias them.
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/emacs-lisp/subr-x.el36
2 files changed, 28 insertions, 12 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 617f39f9b4c..930e1c893b4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -885,6 +885,10 @@ collection).
885+++ 885+++
886** 'car' and 'cdr' compositions 'cXXXr' and 'cXXXXr' are now part of Elisp. 886** 'car' and 'cdr' compositions 'cXXXr' and 'cXXXXr' are now part of Elisp.
887 887
888---
889** 'if-let*', 'when-let*', and 'and-let*' are new in subr-x.el.
890The incumbent 'if-let' and 'when-let' are now aliases.
891
888+++ 892+++
889** The new functions 'make-nearby-temp-file' and 'temporary-file-directory' 893** The new functions 'make-nearby-temp-file' and 'temporary-file-directory'
890can be used for creation of temporary files of remote or mounted directories. 894can be used for creation of temporary files of remote or mounted directories.
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 52331b9ad36..f7a846927c0 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -115,12 +115,16 @@ threading."
115 binding)) 115 binding))
116 bindings))) 116 bindings)))
117 117
118(defmacro if-let (bindings then &rest else) 118(defmacro if-let* (bindings then &rest else)
119 "Process BINDINGS and if all values are non-nil eval THEN, else ELSE. 119 "Bind variables according to VARLIST and eval THEN or ELSE.
120Argument BINDINGS is a list of tuples whose car is a symbol to be 120Each binding is evaluated in turn with `let*', and evaluation
121bound and (optionally) used in THEN, and its cadr is a sexp to be 121stops if a binding value is nil. If all are non-nil, the value
122evalled to set symbol's value. In the special case you only want 122of THEN is returned, or the last form in ELSE is returned.
123to bind a single value, BINDINGS can just be a plain tuple." 123Each element of VARLIST is a symbol (which is bound to nil)
124or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
125In the special case you only want to bind a single value,
126VARLIST can just be a plain tuple.
127\n(fn VARLIST THEN ELSE...)"
124 (declare (indent 2) 128 (declare (indent 2)
125 (debug ([&or (&rest (symbolp form)) (symbolp form)] form body))) 129 (debug ([&or (&rest (symbolp form)) (symbolp form)] form body)))
126 (when (and (<= (length bindings) 2) 130 (when (and (<= (length bindings) 2)
@@ -132,15 +136,23 @@ to bind a single value, BINDINGS can just be a plain tuple."
132 ,then 136 ,then
133 ,@else))) 137 ,@else)))
134 138
135(defmacro when-let (bindings &rest body) 139(defmacro when-let* (bindings &rest body)
136 "Process BINDINGS and if all values are non-nil eval BODY. 140 "Bind variables according to VARLIST and conditionally eval BODY.
137Argument BINDINGS is a list of tuples whose car is a symbol to be 141Each binding is evaluated in turn with `let*', and evaluation
138bound and (optionally) used in BODY, and its cadr is a sexp to be 142stops if a binding value is nil. If all are non-nil, the value
139evalled to set symbol's value. In the special case you only want 143of the last form in BODY is returned.
140to bind a single value, BINDINGS can just be a plain tuple." 144Each element of VARLIST is a symbol (which is bound to nil)
145or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
146In the special case you only want to bind a single value,
147VARLIST can just be a plain tuple.
148\n(fn VARLIST BODY...)"
141 (declare (indent 1) (debug if-let)) 149 (declare (indent 1) (debug if-let))
142 (list 'if-let bindings (macroexp-progn body))) 150 (list 'if-let bindings (macroexp-progn body)))
143 151
152(defalias 'if-let 'if-let*)
153(defalias 'when-let 'when-let*)
154(defalias 'and-let* 'when-let*)
155
144(defsubst hash-table-empty-p (hash-table) 156(defsubst hash-table-empty-p (hash-table)
145 "Check whether HASH-TABLE is empty (has 0 elements)." 157 "Check whether HASH-TABLE is empty (has 0 elements)."
146 (zerop (hash-table-count hash-table))) 158 (zerop (hash-table-count hash-table)))