aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2015-06-27 08:34:44 -0700
committerPaul Eggert2015-06-27 08:35:13 -0700
commit5e3fde03b45877d3e30f859a14c10043e637aa63 (patch)
tree5eec042dddf9bde298a11dfad967e7662e004c56
parent7baae811651d73b3e89c832a5c15ff5b40c82635 (diff)
downloademacs-5e3fde03b45877d3e30f859a14c10043e637aa63.tar.gz
emacs-5e3fde03b45877d3e30f859a14c10043e637aa63.zip
Improve docstring for macroexp-let2
* lisp/emacs-lisp/macroexp.el (macroexp-let2): Improve as per suggestion by RMS in: http://lists.gnu.org/archive/html/emacs-devel/2015-06/msg00621.html Also, rename args to match new doc string.
-rw-r--r--lisp/emacs-lisp/macroexp.el45
1 files changed, 34 insertions, 11 deletions
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index e9af3b08997..57cbec580b0 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -341,21 +341,44 @@ definitions to shadow the loaded ones for use in file byte-compilation."
341 ((memq (car-safe then) '(if cond)) (macroexp-if `(not ,test) else then)) 341 ((memq (car-safe then) '(if cond)) (macroexp-if `(not ,test) else then))
342 (t `(if ,test ,then ,else)))) 342 (t `(if ,test ,then ,else))))
343 343
344(defmacro macroexp-let2 (test var exp &rest exps) 344(defmacro macroexp-let2 (test sym exp &rest body)
345 "Bind VAR to a copyable expression that returns the value of EXP. 345 "Evaluate BODY with SYM bound to an expression for EXP's value.
346This is like \\=`(let ((v ,EXP)) ,EXPS) except that `v' is a new generated 346The intended usage is that BODY generates an expression that
347symbol which EXPS can find in VAR. 347will refer to EXP's value multiple times, but will evaluate
348TEST should be the name of a predicate on EXP checking whether the `let' can 348EXP only once. As BODY generates that expression, it should
349be skipped; if nil, as is usual, `macroexp-const-p' is used." 349use SYM to stand for the value of EXP.
350
351If EXP is a simple, safe expression, then SYM's value is EXP itself.
352Otherwise, SYM's value is a symbol which holds the value produced by
353evaluating EXP. The return value incorporates the value of BODY, plus
354additional code to evaluate EXP once and save the result so SYM can
355refer to it.
356
357If BODY consists of multiple forms, they are all evaluated
358but only the last one's value matters.
359
360TEST is a predicate to determine whether EXP qualifies as simple and
361safe; if TEST is nil, only constant expressions qualify.
362
363Example:
364 (macroexp-let2 nil foo EXP
365 \\=`(* ,foo ,foo))
366generates an expression that evaluates EXP once,
367then returns the square of that value.
368You could do this with
369 (let ((foovar EXP))
370 (* foovar foovar))
371but using `macroexp-let2' produces more efficient code in
372cases where EXP is a constant."
350 (declare (indent 3) (debug (sexp sexp form body))) 373 (declare (indent 3) (debug (sexp sexp form body)))
351 (let ((bodysym (make-symbol "body")) 374 (let ((bodysym (make-symbol "body"))
352 (expsym (make-symbol "exp"))) 375 (expsym (make-symbol "exp")))
353 `(let* ((,expsym ,exp) 376 `(let* ((,expsym ,exp)
354 (,var (if (funcall #',(or test #'macroexp-const-p) ,expsym) 377 (,sym (if (funcall #',(or test #'macroexp-const-p) ,expsym)
355 ,expsym (make-symbol ,(symbol-name var)))) 378 ,expsym (make-symbol ,(symbol-name sym))))
356 (,bodysym ,(macroexp-progn exps))) 379 (,bodysym ,(macroexp-progn body)))
357 (if (eq ,var ,expsym) ,bodysym 380 (if (eq ,sym ,expsym) ,bodysym
358 (macroexp-let* (list (list ,var ,expsym)) 381 (macroexp-let* (list (list ,sym ,expsym))
359 ,bodysym))))) 382 ,bodysym)))))
360 383
361(defmacro macroexp-let2* (test bindings &rest body) 384(defmacro macroexp-let2* (test bindings &rest body)