1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Merge from emacs-24; up to 2012-04-21T14:12:27Z!sdl.web@gmail.com

This commit is contained in:
Glenn Morris 2012-05-08 20:06:08 -07:00
commit 666b903b91
28 changed files with 429 additions and 264 deletions

View file

@ -109,7 +109,7 @@ If @var{environment} is provided, it specifies an alist of macro
definitions that shadow the currently defined macros. Byte compilation
uses this feature.
@smallexample
@example
@group
(defmacro inc (var)
(list 'setq var (list '1+ var)))
@ -131,7 +131,7 @@ uses this feature.
(macroexpand '(inc2 r s))
@result{} (progn (inc r) (inc s)) ; @r{@code{inc} not expanded here.}
@end group
@end smallexample
@end example
@end defun
@ -145,10 +145,10 @@ Repeating the example used for @code{macroexpand} above with
@code{macroexpand-all}, we see that @code{macroexpand-all} @emph{does}
expand the embedded calls to @code{inc}:
@smallexample
@example
(macroexpand-all '(inc2 r s))
@result{} (progn (setq r (1+ r)) (setq s (1+ s)))
@end smallexample
@end example
@end defun
@ -332,7 +332,7 @@ following macro (used to facilitate iteration) illustrates the
problem. This macro allows us to write a ``for'' loop construct.
@findex for
@smallexample
@example
@group
(defmacro for (var from init to final do &rest body)
"Execute a simple \"for\" loop.
@ -363,7 +363,7 @@ For example, (for i from 1 to 10 do (print i))."
@print{}3 9
@result{} nil
@end group
@end smallexample
@end example
@noindent
The arguments @code{from}, @code{to}, and @code{do} in this macro are
@ -373,7 +373,7 @@ in those positions in the macro call.
Here's an equivalent definition simplified through use of backquote:
@smallexample
@example
@group
(defmacro for (var from init to final do &rest body)
"Execute a simple \"for\" loop.
@ -383,7 +383,7 @@ For example, (for i from 1 to 10 do (print i))."
,@@body
(inc ,var))))
@end group
@end smallexample
@end example
Both forms of this definition (with backquote and without) suffer from
the defect that @var{final} is evaluated on every iteration. If
@ -398,7 +398,7 @@ producing an expansion that evaluates the argument expressions exactly
once unless repeated evaluation is part of the intended purpose of the
macro. Here is a correct expansion for the @code{for} macro:
@smallexample
@example
@group
(let ((i 1)
(max 3))
@ -407,11 +407,11 @@ macro. Here is a correct expansion for the @code{for} macro:
(princ (format "%d %d" i square))
(inc i)))
@end group
@end smallexample
@end example
Here is a macro definition that creates this expansion:
@smallexample
@example
@group
(defmacro for (var from init to final do &rest body)
"Execute a simple for loop: (for i from 1 to 10 do (print i))."
@ -421,7 +421,7 @@ Here is a macro definition that creates this expansion:
,@@body
(inc ,var))))
@end group
@end smallexample
@end example
Unfortunately, this fix introduces another problem,
described in the following section.
@ -434,7 +434,7 @@ described in the following section.
follows to make the expansion evaluate the macro arguments the proper
number of times:
@smallexample
@example
@group
(defmacro for (var from init to final do &rest body)
"Execute a simple for loop: (for i from 1 to 10 do (print i))."
@ -446,14 +446,14 @@ number of times:
,@@body
(inc ,var))))
@end group
@end smallexample
@end example
@end ifnottex
The new definition of @code{for} has a new problem: it introduces a
local variable named @code{max} which the user does not expect. This
causes trouble in examples such as the following:
@smallexample
@example
@group
(let ((max 0))
(for x from 0 to 10 do
@ -461,7 +461,7 @@ causes trouble in examples such as the following:
(if (< max this)
(setq max this)))))
@end group
@end smallexample
@end example
@noindent
The references to @code{max} inside the body of the @code{for}, which
@ -477,7 +477,7 @@ put it into the program later. It will never appear anywhere except
where put by @code{for}. Here is a definition of @code{for} that works
this way:
@smallexample
@example
@group
(defmacro for (var from init to final do &rest body)
"Execute a simple for loop: (for i from 1 to 10 do (print i))."
@ -488,7 +488,7 @@ this way:
,@@body
(inc ,var)))))
@end group
@end smallexample
@end example
@noindent
This creates an uninterned symbol named @code{max} and puts it in the