summaryrefslogtreecommitdiff
path: root/doc/lispref/macros.texi
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2012-05-08 20:06:08 -0700
committerGlenn Morris <rgm@gnu.org>2012-05-08 20:06:08 -0700
commit666b903b912ca0aa2b1a034859b752b04f03141a (patch)
treeadd3234ca1ed7c2d5b18422b3f6982b34388d65b /doc/lispref/macros.texi
parent8f6b6da8ecdcd37ecbb83778d35baa02d68621a3 (diff)
parent0a454caf059b4cc050984a41decc2344cd9a083f (diff)
downloademacs-666b903b912ca0aa2b1a034859b752b04f03141a.tar.gz
Merge from emacs-24; up to 2012-04-21T14:12:27Z!sdl.web@gmail.com
Diffstat (limited to 'doc/lispref/macros.texi')
-rw-r--r--doc/lispref/macros.texi36
1 files changed, 18 insertions, 18 deletions
diff --git a/doc/lispref/macros.texi b/doc/lispref/macros.texi
index 3984e5c03aa..27361a5f07e 100644
--- a/doc/lispref/macros.texi
+++ b/doc/lispref/macros.texi
@@ -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