m4-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU M4 source repository branch, master, updated. cvs-readonly-67-


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, master, updated. cvs-readonly-67-gb5b24ec
Date: Tue, 19 Feb 2008 21:06:36 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU M4 source repository".

http://git.sv.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=b5b24ec23ec1f242e8d4f3571ec288d9d03fd58d

The branch, master has been updated
       via  b5b24ec23ec1f242e8d4f3571ec288d9d03fd58d (commit)
       via  daed50d635fad7a37f7d050926dfe04d96af5ebb (commit)
      from  2e81b080376fcc4f3362a0c4810de084371c87d0 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b5b24ec23ec1f242e8d4f3571ec288d9d03fd58d
Author: Eric Blake <address@hidden>
Date:   Tue Feb 19 12:18:05 2008 -0700

    Clean up example on filtering defined symbols.
    
    * doc/m4.texinfo (Foreach, Improved foreach): Document another
    shortcoming in foreach.m4, and improve filter example by using
    foreach2.m4.
    
    Signed-off-by: Eric Blake <address@hidden>

commit daed50d635fad7a37f7d050926dfe04d96af5ebb
Author: Eric Blake <address@hidden>
Date:   Tue Feb 19 08:59:45 2008 -0700

    * src/main.c (usage): Fix typo.
    
    Signed-off-by: Eric Blake <address@hidden>

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog      |    9 ++++++
 doc/m4.texinfo |   81 +++++++++++++++++++++++++++++++++++++------------------
 src/main.c     |    2 +-
 3 files changed, 64 insertions(+), 28 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ba56df5..1832be1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-02-19  Eric Blake  <address@hidden>
+
+       Clean up example on filtering defined symbols.
+       * doc/m4.texinfo (Foreach, Improved foreach): Document another
+       shortcoming in foreach.m4, and improve filter example by using
+       foreach2.m4.
+
+       * src/main.c (usage): Fix typo.
+
 2008-02-18  Eric Blake  <address@hidden>
 
        Avoid some magic numbers.
diff --git a/doc/m4.texinfo b/doc/m4.texinfo
index 571c0dc..011fbfb 100644
--- a/doc/m4.texinfo
+++ b/doc/m4.texinfo
@@ -3362,38 +3362,26 @@ has its own severe flaw.  Whereas the @code{foreach} 
implementation was
 linear, this macro is quadratic in the number of list elements, and is
 much more likely to trip up the limit set by the command line option
 @option{--nesting-limit} (or @option{-L}, @pxref{Limits control, ,
-Invoking m4}).  (It is possible to have robust iteration with linear
-behavior for either list style.  See if you can learn from the best
-elements of both of these implementations to create robust macros; or
address@hidden foreach, , Answers}).
-
-With a robust @code{foreach} implementation, it is possible to create a
-filter on a list of defined symbols.  This next example will find all
-symbols that contain @samp{if}.  Notice the use of @code{dquote} and
address@hidden to ensure that the list of macro names is properly
-quoted; without these, the iteration would be invoking various macros
-with catastrophic effects.  This example also shows a trick for
-generating the correct number of commas in the resulting output.
+Invoking m4}).  Additionally, this implementation does not expand
address@hidden(address@hidden')} very well, when compared with
address@hidden
 
 @comment examples
 @example
 $ @kbd{m4 -I examples}
-include(`quote.m4')include(`foreachq.m4')
address@hidden
-pushdef(`sep', ``, '')
address@hidden
-pushdef(`cleanup', `popdef(`sep', `cleanup')')
address@hidden
-pushdef(`sep', `define(`cleanup',
-  `popdef(`cleanup')')popdef(`sep')')
address@hidden
-foreachq(`macro', dquote(dquote_elt(m4symbols)),
-  `regexp(macro, `.*if.*', `sep`\&'')')
address@hidden, ifelse, shift
-cleanup
+include(`foreach.m4')include(`foreachq.m4')
 @result{}
+foreach(`name', `(`a', `b')', ` defn(`name')')
address@hidden a b
+foreachq(`name', ``a', `b'', ` defn(`name')')
address@hidden _arg1(`a', `b') _arg1(shift(`a', `b'))
 @end example
 
+It is possible to have robust iteration with linear behavior and sane
address@hidden contents for either list style.  See if you can learn
+from the best elements of both of these implementations to create robust
+macros (or @pxref{Improved foreach, , Answers}).
+
 @node Debugging
 @chapter How to debug macros and input
 
@@ -8405,7 +8393,9 @@ Note that the fixed version calls unquoted helper macros 
in
 in turn must re-supply the layer of quotes lost in the macro invocation.
 Contrast the use of @address@hidden, which quotes the first list
 element, with @address@hidden of the earlier implementation that
-returned the first list element directly.
+returned the first list element directly.  Additionally, by calling the
+helper method immediately, the @samp{defn(address@hidden')} no longer
+contains unexpanded macros.
 
 The astute m4 programmer might notice that the solution above still uses
 more memory, and thus more time, than strictly necessary.  Note that
@@ -8501,10 +8491,43 @@ foreach(`x', `(`1', `2', `3', `4')', `x
 @error{}m4trace: -3- shift(``4'')
 @end example
 
address@hidden filtering defined symbols
address@hidden subset of defined symbols
address@hidden defined symbols, filtering
+With a robust @code{foreachq} implementation, it is possible to create a
+filter on a list of defined symbols.  This next example will find all
+symbols that contain @samp{if} or @samp{def}, via two different
+approaches.  In the first approach, @code{dquote_elt} is used to
+overquote each list element, then @code{dquote} forms the list; that
+way, the iterator @code{macro} can be expanded in place because its
+contents are already quoted.  This approach also uses a self-modifying
+macro @code{sep} to provide the correct number of commas.  In the second
+approach, the iterator @code{macro} contains live text, so it must be
+used with @code{defn} to avoid unintentional expansion.  The correct
+number of commas is achieved by using @code{shift} to ignore the first
+one, although a leading space still remains.
+
address@hidden examples
address@hidden
+$ @kbd{m4 -I examples}
+include(`quote.m4')include(`foreachq2.m4')
address@hidden
+pushdef(`sep', `define(`sep', ``, '')')
address@hidden
+foreachq(`macro', dquote(dquote_elt(m4symbols)),
+  `regexp(macro, `.*if.*', `sep`\&'')')
address@hidden, ifelse, shift
+popdef(`sep')
address@hidden
+shift(foreachq(`macro', dquote(m4symbols),
+  `regexp(defn(`macro'), `def', `,` ''dquote(defn(`macro')))'))
address@hidden define, defn, dumpdef, ifdef, popdef, pushdef, undefine
address@hidden example
+
 In summary, recursion over list elements is trickier than it appeared at
 first glance, but provides a powerful idiom within @code{m4} processing.
 As a final demonstration, both list styles are now able to handle
-several scenarios that would wreak havoc on the original
+several scenarios that would wreak havoc on one or both of the original
 implementations.  This points out one other difference between the
 list styles.  @code{foreach} evaluates unquoted list elements only once,
 in preparation for calling @address@hidden, similary for
@@ -8538,6 +8561,10 @@ foreach(`x', `(`,')', `<x>') / foreachq(`x', ``,'', 
`<x>')
 dnl 2-element list of unbalanced parentheses
 foreach(`x', `(`(', `)')', `<x>') / foreachq(`x', ``(', `)'', `<x>')
 @result{}<(><)> / <(><)>
+define(`ab', `oops')dnl using defn(`iterator')
+foreach(`x', `(`a', `b')', `defn(`x')') /dnl
+ foreachq(`x', ``a', `b'', `defn(`x')')
address@hidden / ab
 define(`active', `ACT, IVE')
 @result{}
 traceon(`active')
diff --git a/src/main.c b/src/main.c
index e36c826..a11e821 100644
--- a/src/main.c
+++ b/src/main.c
@@ -75,7 +75,7 @@ usage (int status)
       fputs (_("\
 Process macros in FILEs.\n\
 If no FILE or if FILE is `-', standard input is read.  If no FILE, and both\n\
-standard input and standard output are terminals, -i is implied.\n\
+standard input and standard error are terminals, -i is implied.\n\
 "), stdout);
       puts ("");
       fputs (_("\


hooks/post-receive
--
GNU M4 source repository




reply via email to

[Prev in Thread] Current Thread [Next in Thread]