diff options
| author | Paul Eggert | 2015-06-27 08:34:44 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-06-27 08:35:13 -0700 |
| commit | 5e3fde03b45877d3e30f859a14c10043e637aa63 (patch) | |
| tree | 5eec042dddf9bde298a11dfad967e7662e004c56 | |
| parent | 7baae811651d73b3e89c832a5c15ff5b40c82635 (diff) | |
| download | emacs-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.el | 45 |
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. |
| 346 | This is like \\=`(let ((v ,EXP)) ,EXPS) except that `v' is a new generated | 346 | The intended usage is that BODY generates an expression that |
| 347 | symbol which EXPS can find in VAR. | 347 | will refer to EXP's value multiple times, but will evaluate |
| 348 | TEST should be the name of a predicate on EXP checking whether the `let' can | 348 | EXP only once. As BODY generates that expression, it should |
| 349 | be skipped; if nil, as is usual, `macroexp-const-p' is used." | 349 | use SYM to stand for the value of EXP. |
| 350 | |||
| 351 | If EXP is a simple, safe expression, then SYM's value is EXP itself. | ||
| 352 | Otherwise, SYM's value is a symbol which holds the value produced by | ||
| 353 | evaluating EXP. The return value incorporates the value of BODY, plus | ||
| 354 | additional code to evaluate EXP once and save the result so SYM can | ||
| 355 | refer to it. | ||
| 356 | |||
| 357 | If BODY consists of multiple forms, they are all evaluated | ||
| 358 | but only the last one's value matters. | ||
| 359 | |||
| 360 | TEST is a predicate to determine whether EXP qualifies as simple and | ||
| 361 | safe; if TEST is nil, only constant expressions qualify. | ||
| 362 | |||
| 363 | Example: | ||
| 364 | (macroexp-let2 nil foo EXP | ||
| 365 | \\=`(* ,foo ,foo)) | ||
| 366 | generates an expression that evaluates EXP once, | ||
| 367 | then returns the square of that value. | ||
| 368 | You could do this with | ||
| 369 | (let ((foovar EXP)) | ||
| 370 | (* foovar foovar)) | ||
| 371 | but using `macroexp-let2' produces more efficient code in | ||
| 372 | cases 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) |