autoconf-commit
[Top][All Lists]
Advanced

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

[SCM] GNU Autoconf source repository branch, master, updated. v2.63-65-g


From: Eric Blake
Subject: [SCM] GNU Autoconf source repository branch, master, updated. v2.63-65-gc6b172e
Date: Fri, 17 Oct 2008 22:37:11 +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 Autoconf source repository".

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

The branch, master has been updated
       via  c6b172ee196b189c4074f5e623f22d9b47decb6f (commit)
       via  a00c4430bad94ff1062e3fcfc7358f5eb0bd81bd (commit)
       via  92f34215fcf5e13206f7632ea832b48ce4dca702 (commit)
       via  f4ace96990c107f028a496ebd45ff031d7302a7b (commit)
      from  093eca1787cb8749b0061116a1f9ee0a90ea6e54 (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 c6b172ee196b189c4074f5e623f22d9b47decb6f
Author: Eric Blake <address@hidden>
Date:   Wed Oct 15 11:55:45 2008 -0600

    Add m4_curry.
    
    * lib/m4sugar/m4sugar.m4 (m4_curry, _m4_curry): New macros.
    * tests/m4sugar.at (m4@&address@hidden): Rename...
    (m4@&address@hidden and m4@&address@hidden): ...and add currying tests.
    * doc/autoconf.texi (Looping constructs) <m4_map_args>: Document
    currying as a way to add parameters.
    (Evaluation Macros) <m4_curry>: Document the new macro.
    * NEWS: Likewise.
    
    Signed-off-by: Eric Blake <address@hidden>

commit a00c4430bad94ff1062e3fcfc7358f5eb0bd81bd
Author: Eric Blake <address@hidden>
Date:   Fri Oct 17 16:12:17 2008 -0600

    Improve suggested test filtering.
    
    * lib/m4sugar/m4sh.m4 (_AS_DETECT_SUGGESTED_PRUNE): New macro,
    extracted from...
    (_AS_DETECT_BETTER_SHELL): ...here, to use faster API.  No need to
    check for an empty required set.
    
    Signed-off-by: Eric Blake <address@hidden>

commit 92f34215fcf5e13206f7632ea832b48ce4dca702
Author: Eric Blake <address@hidden>
Date:   Mon Oct 13 15:37:31 2008 -0600

    Add m4_set_map.
    
    * lib/m4sugar/m4sugar.m4 (m4_set_foreach): New macro.
    * tests/m4sugar.at (m4@&address@hidden): Enhance test.
    * doc/autoconf.texi (Set manipulation Macros) <m4_set_map>:
    Document it.
    * NEWS: Likewise.
    
    Signed-off-by: Eric Blake <address@hidden>

commit f4ace96990c107f028a496ebd45ff031d7302a7b
Author: Eric Blake <address@hidden>
Date:   Mon Oct 13 10:46:40 2008 -0600

    Document m4_map_args.
    
    * lib/m4sugar/m4sugar.m4 (m4_transform, m4_transform_pair):
    Rename...
    (m4_map_args, m4_map_args_pair): ...to these names, and document.
    (m4_version_unletter): Use the interface.
    * lib/m4sugar/foreach.m4 (m4_map_args, m4_map_args_pair)
    (_m4_map_args_, _m4_map_args_pair_, _m4_map_args_pair_end):
    Perform same renames.
    * lib/m4sugar/m4sh.m4 (AS_CASE, AS_IF): Adjust callers.
    * tests/m4sugar.at (m4@&address@hidden): New test.
    (recursion): Adjust caller.
    * tests/m4sh.at (AS@&address@hidden and AS@&address@hidden): Likewise.
    * doc/autoconf.texi (Looping constructs) <m4_map_args>: Document
    this interface.
    * NEWS: Mention the new macros.
    
    Signed-off-by: Eric Blake <address@hidden>

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

Summary of changes:
 ChangeLog              |   40 +++++++++++++++++++
 NEWS                   |    3 +-
 doc/autoconf.texi      |   86 ++++++++++++++++++++++++++++++++++++++++-
 lib/m4sugar/foreach.m4 |   26 ++++++------
 lib/m4sugar/m4sh.m4    |   31 ++++++++-------
 lib/m4sugar/m4sugar.m4 |   56 +++++++++++++++++++-------
 tests/m4sh.at          |    2 +-
 tests/m4sugar.at       |  100 ++++++++++++++++++++++++++++++++++++++----------
 8 files changed, 279 insertions(+), 65 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 32bf23b..79100bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,45 @@
 2008-10-17  Eric Blake  <address@hidden>
 
+       Add m4_curry.
+       * lib/m4sugar/m4sugar.m4 (m4_curry, _m4_curry): New macros.
+       * tests/m4sugar.at (m4@&address@hidden): Rename...
+       (m4@&address@hidden and m4@&address@hidden): ...and add currying tests.
+       * doc/autoconf.texi (Looping constructs) <m4_map_args>: Document
+       currying as a way to add parameters.
+       (Evaluation Macros) <m4_curry>: Document the new macro.
+       * NEWS: Likewise.
+
+       Improve suggested test filtering.
+       * lib/m4sugar/m4sh.m4 (_AS_DETECT_SUGGESTED_PRUNE): New macro,
+       extracted from...
+       (_AS_DETECT_BETTER_SHELL): ...here, to use faster API.  No need to
+       check for an empty required set.
+
+       Add m4_set_map.
+       * lib/m4sugar/m4sugar.m4 (m4_set_foreach): New macro.
+       * tests/m4sugar.at (m4@&address@hidden): Enhance test.
+       * doc/autoconf.texi (Set manipulation Macros) <m4_set_map>:
+       Document it.
+       * NEWS: Likewise.
+
+       Document m4_map_args.
+       * lib/m4sugar/m4sugar.m4 (m4_transform, m4_transform_pair):
+       Rename...
+       (m4_map_args, m4_map_args_pair): ...to these names, and document.
+       (m4_version_unletter): Use the interface.
+       * lib/m4sugar/foreach.m4 (m4_map_args, m4_map_args_pair)
+       (_m4_map_args_, _m4_map_args_pair_, _m4_map_args_pair_end):
+       Perform same renames.
+       * lib/m4sugar/m4sh.m4 (AS_CASE, AS_IF): Adjust callers.
+       * tests/m4sugar.at (m4@&address@hidden): New test.
+       (recursion): Adjust caller.
+       * tests/m4sh.at (AS@&address@hidden and AS@&address@hidden): Likewise.
+       * doc/autoconf.texi (Looping constructs) <m4_map_args>: Document
+       this interface.
+       * NEWS: Mention the new macros.
+
+2008-10-17  Eric Blake  <address@hidden>
+
        Reduce vertical whitespace in configure.
        * lib/autoconf/general.m4 (AC_INIT): Silence newline output during
        m4 side effect initializations.
diff --git a/NEWS b/NEWS
index 72eab50..147639b 100644
--- a/NEWS
+++ b/NEWS
@@ -13,7 +13,8 @@ GNU Autoconf NEWS - User visible changes.
 ** Configure scripts now use shell functions.
 
 ** The following m4sugar macros are new:
-   m4_default_quoted
+   m4_curry  m4_default_quoted  m4_map_args  m4_map_args_pair
+   m4_set_map
 
 ** The following documented m4sh macros are new:
    AS_LINENO_PREPARE  AS_ME_PREPARE  AS_VAR_COPY
diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 67c1b42..3078869 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10928,6 +10928,65 @@ m4_count(m4_map_sep([m4_echo], [[,]], [[[a]], [[b]]]))
 @end example
 @end defmac
 
address@hidden m4_map_args (@var{macro}, @address@hidden)
address@hidden
+Repeatedly invoke @var{macro} with each successive @var{arg} as its only
+argument.  In the following example, three solutions are presented with
+the same expansion; the solution using @code{m4_map_args} is the most
+efficient.
address@hidden
+m4_define([active], [ACTIVE])dnl
+m4_foreach([var], [[plain], [active]], [ m4_echo(m4_defn([var]))])
address@hidden plain active
+m4_map([ m4_echo], [[[plain]], [[active]]])
address@hidden plain active
+m4_map_args([ m4_echo], [plain], [active])
address@hidden plain active
address@hidden example
+
+In cases where it is useful to operate on additional parameters besides
+the list elements, the macro @code{m4_curry} can be used in @var{macro}
+to supply the argument currying necessary to generate the desired
+argument list.  In the following example, @code{list_add_n} is more
+efficient than @code{list_add_x}.
+
address@hidden
+m4_define([list], [[1], [2], [3]])dnl
+m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
+dnl list_add_n(N, ARG...)
+dnl Output a list consisting of each ARG added to N
+m4_define([list_add_n],
+[m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@@)))])dnl
+list_add_n([1], list)
address@hidden,3,4
+list_add_n([2], list)
address@hidden,4,5
+m4_define([list_add_x],
+[m4_shift(m4_foreach([var], m4_dquote(m4_shift($@@)),
+  [,add([$1],m4_defn([var]))]))])dnl
+list_add_x([1], list)
address@hidden,3,4
address@hidden example
address@hidden defmac
+
address@hidden m4_map_args_pair (@var{macro}, @dvar{macro-end, macro}, @
+  @address@hidden)
address@hidden
+For every pair of arguments @var{arg}, invoke @var{macro} with two
+arguments.  If there is an odd number of arguments, invoke
address@hidden, which defaults to @var{macro}, with the remaining
+argument.
+
address@hidden
+m4_map_args_pair([, m4_reverse], [], [1], [2], [3])
address@hidden, 2, 1, 3
+m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])
address@hidden, 2, 1, [3]
+m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])
address@hidden, 2, 1, 4, 3
address@hidden example
address@hidden defmac
+
 @defmac m4_shiftn (@var{count}, @dots{})
 @defmacx m4_shift2 (@dots{})
 @defmacx m4_shift3 (@dots{})
@@ -10975,6 +11034,19 @@ This macro returns the decimal count of the number of 
arguments it was
 passed.
 @end defmac
 
address@hidden m4_curry (@var{macro}, @address@hidden)
address@hidden
+This macro performs argument currying.  The expansion of this macro is
+another macro name that expects exactly one argument; that argument is
+then appended to the @var{arg} list, and then @var{macro} is expanded
+with the resulting argument list.
+
address@hidden
+m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
address@hidden, 2, 1
address@hidden example
address@hidden defmac
+
 @defmac m4_do (@var{arg}, @dots{})
 @msindex{do}
 This macro loops over its arguments and expands each @var{arg} in
@@ -11716,6 +11788,17 @@ m4_set_empty([b], [0], [m4_count(m4_set_list([b]))])
 @end example
 @end defmac
 
address@hidden m4_set_map (@var{set}, @var{action})
address@hidden
+For each element in the set @var{set}, expand @var{action} with a single
+argument of the set element.  Behavior is unspecified if @var{action}
+recursively lists the contents of @var{set} (although listing other sets
+is acceptable), or if it modifies the set in any way other than removing
+the element passed as an argument.  This macro is faster than the
+corresponding
address@hidden(address@hidden(address@hidden))}.
address@hidden defmac
+
 @defmac m4_set_remove (@var{set}, @var{value}, @ovar{if-present}, @
  @ovar{if-absent})
 @msindex{set_remove}
@@ -11723,7 +11806,8 @@ If @var{value} is an element in the set @var{set}, then 
remove it and
 expand @var{if-present}.  Otherwise expand @var{if-absent}.  This macro
 operates in constant time so that multiple removals will scale linearly
 rather than quadratically; but when used outside of
address@hidden, it leaves memory occupied until the set is later
address@hidden or @code{m4_set_map}, it leaves memory occupied
+until the set is later
 compacted by @code{m4_set_contents} or @code{m4_set_list}.  Several
 other set operations are then less efficient between the time of element
 removal and subsequent memory compaction, but still maintain their
diff --git a/lib/m4sugar/foreach.m4 b/lib/m4sugar/foreach.m4
index bfad301..9dc02e1 100644
--- a/lib/m4sugar/foreach.m4
+++ b/lib/m4sugar/foreach.m4
@@ -270,33 +270,33 @@ m4_define([_m4_map],
 m4_define([_m4_map_],
 [[$$1, [$$2])]])
 
-# m4_transform(EXPRESSION, ARG...)
-# --------------------------------
+# m4_map_args(EXPRESSION, ARG...)
+# -------------------------------
 # Expand EXPRESSION([ARG]) for each argument.  More efficient than
 # m4_foreach([var], [ARG...], [EXPRESSION(m4_defn([var]))])
 #
-# Invoke the temporary macro _m4_transform, defined as:
-#   $1([$2])[]$1([$3])[]...$1([$m])[]_m4_popdef([_m4_transform])
-m4_define([m4_transform],
+# Invoke the temporary macro _m4_map_args, defined as:
+#   $1([$2])[]$1([$3])[]...$1([$m])[]_m4_popdef([_m4_map_args])
+m4_define([m4_map_args],
 [m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
        [$#], [1], [],
        [m4_define([_$0], m4_pushdef([_$0])_m4_for([_$0], [2], [$#], [1],
    [_$0_([1], _$0)])[_m4_popdef([_$0])])_$0($@)])])
 
-m4_define([_m4_transform_],
+m4_define([_m4_map_args_],
 [[$$1([$$2])[]]])
 
-# m4_transform_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
-# --------------------------------------------------------------
+# m4_map_args_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
+# -------------------------------------------------------------
 # Perform a pairwise grouping of consecutive ARGs, by expanding
 # EXPRESSION([ARG1], [ARG2]).  If there are an odd number of ARGs, the
 # final argument is expanded with END-EXPR([ARGn]).
 #
-# Build the temporary macro _m4_transform_pair, with the $2([$m+1])
+# Build the temporary macro _m4_map_args_pair, with the $2([$m+1])
 # only output if $# is odd:
 #   $1([$3], [$4])[]$1([$5], [$6])[]...$1([$m-1],
-#   [$m])[]m4_default([$2], [$1])([$m+1])[]_m4_popdef([_m4_transform_pair])
-m4_define([m4_transform_pair],
+#   [$m])[]m4_default([$2], [$1])([$m+1])[]_m4_popdef([_m4_map_args_pair])
+m4_define([m4_map_args_pair],
 [m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
        [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])],
        [$#], [2], [],
@@ -305,10 +305,10 @@ m4_define([m4_transform_pair],
    m4_eval([$# / 2 * 2 - 1]), [2], [_$0_([1], _$0, m4_incr(_$0))])_$0_end(
    [1], [2], [$#])[_m4_popdef([_$0])])_$0($@)])])
 
-m4_define([_m4_transform_pair_],
+m4_define([_m4_map_args_pair_],
 [[$$1([$$2], [$$3])[]]])
 
-m4_define([_m4_transform_pair_end],
+m4_define([_m4_map_args_pair_end],
 [m4_if(m4_eval([$3 & 1]), [1], [[m4_default([$$2], [$$1])([$$3])[]]])])
 
 # m4_join(SEP, ARG1, ARG2...)
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 1feff8f..75b8d84 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -173,6 +173,14 @@ m4_defun([_AS_DETECT_SUGGESTED],
 ])])
 
 
+# _AS_DETECT_SUGGESTED_PRUNE(TEST)
+# --------------------------------
+# If TEST is also a required test, remove it from the set of suggested tests.
+m4_define([_AS_DETECT_SUGGESTED_PRUNE],
+[m4_set_contains([_AS_DETECT_REQUIRED_BODY], [$1],
+                [m4_set_remove([_AS_DETECT_SUGGESTED_BODY], [$1])])])
+
+
 # _AS_DETECT_BETTER_SHELL
 # -----------------------
 # The real workhorse for detecting a shell with the correct
@@ -190,18 +198,13 @@ m4_defun([_AS_DETECT_SUGGESTED],
 m4_defun([_AS_DETECT_BETTER_SHELL],
 [if test "x$CONFIG_SHELL" = x; then
 dnl Remove any tests from suggested that are also required
-  m4_set_foreach([_AS_DETECT_SUGGESTED_BODY], [AS_snippet],
-                [m4_set_contains([_AS_DETECT_REQUIRED_BODY],
-                                 _m4_defn([AS_snippet]),
-                                 [m4_set_remove([_AS_DETECT_SUGGESTED_BODY],
-                                                _m4_defn([AS_snippet]))])])dnl
-  m4_set_empty([_AS_DETECT_REQUIRED_BODY], [as_have_required=yes],
-    [as_bourne_compatible="AS_ESCAPE(m4_expand([_AS_BOURNE_COMPATIBLE]))"
-    
as_required="AS_ESCAPE(m4_expand(m4_set_contents([_AS_DETECT_REQUIRED_BODY])))"
-    
as_suggested="AS_ESCAPE(m4_expand(m4_set_contents([_AS_DETECT_SUGGESTED_BODY])))"
-    AS_IF([_AS_RUN(["$as_required"])],
-         [as_have_required=yes],
-         [as_have_required=no])])
+  m4_set_map([_AS_DETECT_SUGGESTED_BODY], [_AS_DETECT_SUGGESTED_PRUNE])dnl
+  as_bourne_compatible="AS_ESCAPE(m4_expand([_AS_BOURNE_COMPATIBLE]))"
+  
as_required="AS_ESCAPE(m4_expand(m4_set_contents([_AS_DETECT_REQUIRED_BODY])))"
+  
as_suggested="AS_ESCAPE(m4_expand(m4_set_contents([_AS_DETECT_SUGGESTED_BODY])))"
+  AS_IF([_AS_RUN(["$as_required"])],
+       [as_have_required=yes],
+       [as_have_required=no])
   AS_IF([test x$as_have_required = xyes && _AS_RUN(["$as_suggested"])],
     [],
     [as_candidate_shells=
@@ -490,7 +493,7 @@ m4_define([_AS_CASE_DEFAULT],
 m4_defun([AS_CASE],
 [m4_ifval([$2$3],
 [case $1 in
-m4_transform_pair([_$0], [_$0_DEFAULT], m4_shift($@))dnl
+m4_map_args_pair([_$0], [_$0_DEFAULT], m4_shift($@))dnl
 esac
 ])dnl
 ])# AS_CASE
@@ -535,7 +538,7 @@ m4_defun([AS_IF],
 [m4_ifval([$2$3],
 [if $1; then
   m4_default([$2], [:])
-m4_transform_pair([_$0], [_$0_ELSE], m4_shift2($@))dnl
+m4_map_args_pair([_$0], [_$0_ELSE], m4_shift2($@))dnl
 fi
 ])dnl
 ])# AS_IF
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 681f4b0..ee8ee63 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -726,6 +726,20 @@ m4_define([_m4_apply],
 m4_define([m4_count], [$#])
 
 
+# m4_curry(MACRO, ARG...)
+# -----------------------
+# Perform argument currying.  The expansion of this macro is another
+# macro that takes exactly one argument, appends it to the end of the
+# original ARG list, then invokes MACRO.  For example:
+#   m4_curry([m4_curry], [m4_reverse], [1])([2])([3]) => 3, 2, 1
+# Not quite as practical as m4_incr, but you could also do:
+#   m4_define([add], [m4_eval(([$1]) + ([$2]))])
+#   m4_define([add_one], [m4_curry([add], [1])])
+#   add_one()([2]) => 3
+m4_define([m4_curry], [$1(m4_shift($@,)_$0])
+m4_define([_m4_curry],               [[$1])])
+
+
 # m4_do(STRING, ...)
 # ------------------
 # This macro invokes all its arguments (in sequence, of course).  It is
@@ -1106,34 +1120,34 @@ m4_define([_m4_map],
 [m4_if([$#], [2], [],
        [$1, [$3])$0([$1], m4_shift2($@))])])
 
-# m4_transform(EXPRESSION, ARG...)
-# --------------------------------
+# m4_map_args(EXPRESSION, ARG...)
+# -------------------------------
 # Expand EXPRESSION([ARG]) for each argument.  More efficient than
 # m4_foreach([var], [ARG...], [EXPRESSION(m4_defn([var]))])
 #
 # Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_transform],
+m4_define([m4_map_args],
 [m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
        [$#], [1], [],
        [$#], [2], [$1([$2])[]],
        [$1([$2])[]$0([$1], m4_shift2($@))])])
 
 
-# m4_transform_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
-# --------------------------------------------------------------
+# m4_map_args_pair(EXPRESSION, [END-EXPR = EXPRESSION], ARG...)
+# -------------------------------------------------------------
 # Perform a pairwise grouping of consecutive ARGs, by expanding
 # EXPRESSION([ARG1], [ARG2]).  If there are an odd number of ARGs, the
 # final argument is expanded with END-EXPR([ARGn]).
 #
 # For example:
 #   m4_define([show], [($*)m4_newline])dnl
-#   m4_transform_pair([show], [], [a], [b], [c], [d], [e])dnl
+#   m4_map_args_pair([show], [], [a], [b], [c], [d], [e])dnl
 #   => (a,b)
 #   => (c,d)
 #   => (e)
 #
 # Please keep foreach.m4 in sync with any adjustments made here.
-m4_define([m4_transform_pair],
+m4_define([m4_map_args_pair],
 [m4_if([$#], [0], [m4_fatal([$0: too few arguments: $#])],
        [$#], [1], [m4_fatal([$0: too few arguments: $#: $1])],
        [$#], [2], [],
@@ -2387,9 +2401,9 @@ m4_define([m4_sign],
 #   Nl -> (N+1).-1.(l#)
 #
 # for example:
-#   [2.14a] -> [2.14+1.-1.[0r36:a]] -> 2.15.-1.10
-#   [2.14b] -> [2.15+1.-1.[0r36:b]] -> 2.15.-1.11
-#   [2.61aa.b] -> [2.61+1.-1.[0r36:aa],+1.-1.[0r36:b]] -> 2.62.-1.370.1.-1.11
+#   [2.14a] -> [2,14+1,-1,[0r36:a]] -> 2.15.-1.10
+#   [2.14b] -> [2,15+1,-1,[0r36:b]] -> 2.15.-1.11
+#   [2.61aa.b] -> [2.61,1,-1,[0r36:aa],+1,-1,[0r36:b]] -> 2.62.-1.370.1.-1.11
 #
 # This macro expects reasonable version numbers, but can handle double
 # letters and does not expand any macros.  Original version strings can
@@ -2397,11 +2411,10 @@ m4_define([m4_sign],
 #
 # Inline constant expansions, to avoid m4_defn overhead.
 # _m4_version_unletter is the real workhorse used by m4_version_compare,
-# but since [0r36:a] is less readable than 10, we provide a wrapper for
-# human use.
+# but since [0r36:a] and commas are less readable than 10 and dots, we
+# provide a wrapper for human use.
 m4_define([m4_version_unletter],
-[m4_map_sep([m4_eval], [.],
-           m4_dquote(m4_dquote_elt(m4_unquote(_$0([$1])))))])
+[m4_substr(m4_map_args([.m4_eval], m4_unquote(_$0([$1]))), [1])])
 m4_define([_m4_version_unletter],
 [m4_bpatsubst(m4_translit([[[$1]]], [.-], [,,]),]dnl
 m4_dquote(m4_dquote(m4_defn([m4_cr_Letters])))[[+],
@@ -2718,6 +2731,19 @@ m4_define([m4_set_listc],
          [_m4_set_contents_1])([$1])_m4_set_contents_2([$1],
               [,_m4_defn([_m4_set_($1)])])])
 
+# m4_set_map(SET, ACTION)
+# -----------------------
+# For each element of SET, expand ACTION with a single argument of the
+# current element.  ACTION should not recursively list SET's contents,
+# add elements to SET, nor delete any element from SET except the one
+# passed as an argument.  The order that the elements are visited in
+# is not guaranteed.  This is faster than the corresponding
+#   m4_map_args([ACTION]m4_set_listc([SET]))
+m4_define([m4_set_map],
+[m4_ifdef([_m4_set_cleanup($1)],
+    [_m4_set_contents_1c], [_m4_set_contents_1])([$1])_m4_set_contents_2([$1],
+       [$2(_m4_defn([_m4_set_($1)]))])])
+
 # m4_set_remove(SET, VALUE, [IF-PRESENT], [IF-ABSENT])
 # ----------------------------------------------------
 # If VALUE is an element of SET, delete it and expand IF-PRESENT.
@@ -2727,7 +2753,7 @@ m4_define([m4_set_listc],
 #
 # Optimize if the element being removed is the most recently added,
 # since defining _m4_set_cleanup($1) slows down so many other macros.
-# In particular, this plays well with m4_set_foreach.
+# In particular, this plays well with m4_set_foreach and m4_set_map.
 m4_define([m4_set_remove],
 [m4_set_contains([$1], [$2], [_m4_set_size([$1],
     [m4_decr])m4_if(_m4_defn([_m4_set([$1])]), [$2],
diff --git a/tests/m4sh.at b/tests/m4sh.at
index 5a5ebec..73438fb 100644
--- a/tests/m4sh.at
+++ b/tests/m4sh.at
@@ -724,7 +724,7 @@ AT_CLEANUP
 ## ------------------- ##
 
 AT_SETUP([AS@&address@hidden and AS@&address@hidden)
-AT_KEYWORDS([m4sh m4@&address@hidden)
+AT_KEYWORDS([m4sh m4@&address@hidden)
 
 AT_DATA_M4SH([script.as], [[dnl
 AS_INIT
diff --git a/tests/m4sugar.at b/tests/m4sugar.at
index 89109c6..f34bca3 100644
--- a/tests/m4sugar.at
+++ b/tests/m4sugar.at
@@ -37,21 +37,6 @@ AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
 ])# AT_CHECK_M4SUGAR_TEXT
 
 
-# Order of the tests:
-# - m4_warn
-#
-# - m4_require
-# uses warn/error code.
-#
-# - m4_split
-#
-# - m4_append
-#
-# - m4_join
-#
-# - m4_text_wrap
-# uses m4_split code.
-
 ## --------- ##
 ## m4_defn.  ##
 ## --------- ##
@@ -866,6 +851,73 @@ hi
 AT_CLEANUP
 
 
+## ---------------------------------- ##
+## m4_map_args{,_pair} and m4_curry.  ##
+## ---------------------------------- ##
+
+AT_SETUP([m4@&address@hidden and m4@&address@hidden)
+AT_KEYWORDS([m4@&address@hidden m4@&address@hidden)
+
+dnl First, make sure we can curry in isolation.
+AT_CHECK_M4SUGAR_TEXT(
+[[m4_curry([m4_echo])([1])
+m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
+m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
+m4_define([add_one], [m4_curry([add], [1])])dnl
+add_one()([4])
+]],
+[[1
+3, 2, 1
+5
+]])
+
+dnl Now, check that we can map a list of arguments.
+AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])dnl
+m4_map_args([ m4_echo])
+m4_map_args([ m4_echo], [plain], [active])
+m4_map_args([m4_unquote], [plain], [active])
+m4_map_args_pair([, m4_reverse], [])
+m4_map_args_pair([, m4_reverse], [], [1])
+m4_map_args_pair([, m4_reverse], [], [1], [2])
+m4_map_args_pair([, m4_reverse], [], [1], [2], [3])
+m4_map_args_pair([, m4_reverse], [], [1], [2], [3], [4])
+m4_map_args_pair([, m4_reverse], [, m4_dquote], [1])
+m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2])
+m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])
+m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])
+]],
+[[
+ plain active
+plainACTIVE
+
+, 1
+, 2, 1
+, 2, 1, 3
+, 2, 1, 4, 3
+, [1]
+, 2, 1
+, 2, 1, [3]
+, 2, 1, 4, 3
+]])
+
+dnl Finally, put the two concepts together, to show the real power of the API.
+AT_CHECK_M4SUGAR_TEXT(
+[[m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
+m4_define([list], [[-1], [0], [1]])dnl
+dnl list_add_n(value, arg...)
+dnl add VALUE to each ARG and output the resulting list
+m4_define([list_add_n],
+  [m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@)))])
+list_add_n([1], list)
+list_add_n([2], list)
+]], [[
+0,1,2
+1,2,3
+]])
+
+AT_CLEANUP
+
+
 ## ------------ ##
 ## m4_combine.  ##
 ## ------------ ##
@@ -981,7 +1033,7 @@ AT_SETUP([recursion])
 AT_KEYWORDS([m4@&address@hidden m4@&address@hidden m4@&address@hidden 
m4@&address@hidden
 m4@&address@hidden m4@&address@hidden m4@&address@hidden m4@&address@hidden 
m4@&address@hidden
 m4@&address@hidden m4@&address@hidden m4@&address@hidden m4@&address@hidden 
m4@&address@hidden m4@&address@hidden
-m4@&address@hidden m4@&address@hidden m4@&address@hidden)
+m4@&address@hidden m4@&address@hidden m4@&address@hidden)
 
 dnl This test completes in a reasonable time if m4_foreach is linear,
 dnl but thrashes if it is quadratic.  If we are testing with m4 1.4.x,
@@ -1009,7 +1061,7 @@ m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), 
[a2], [A])
 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
-m4_count(m4_transform_pair([,m4_quote], []m4_transform([,m4_echo]m4_for([i],
+m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
   [1], [10000], [], [,i]))))
 m4_divert_pop(0)
 ]])
@@ -1066,7 +1118,7 @@ m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), 
[a2], [A])
 m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
 m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
 m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
-m4_count(m4_transform_pair([,m4_quote], []m4_transform([,m4_echo]m4_for([i],
+m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
   [1], [10000], [], [,i]))))
 m4_divert_pop(0)
 ]])
@@ -1098,7 +1150,8 @@ AT_SETUP([m4@&address@hidden)
 AT_KEYWORDS([m4@&address@hidden m4@&address@hidden m4@&address@hidden
 m4@&address@hidden m4@&address@hidden m4@&address@hidden m4@&address@hidden
 m4@&address@hidden m4@&address@hidden m4@&address@hidden m4@&address@hidden
-m4@&address@hidden m4@&address@hidden m4@&address@hidden m4@&address@hidden)
+m4@&address@hidden m4@&address@hidden m4@&address@hidden m4@&address@hidden
+m4@&address@hidden)
 
 # Simple tests
 AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
@@ -1123,6 +1176,8 @@ m4_set_difference([a], [b])
 m4_set_difference([b], [a])
 m4_set_intersection([a], [b])
 m4_set_union([a], [b])
+m4_define([printodd], [m4_if(m4_eval([$1 & 1]), [1], [:$1])])dnl
+m4_set_map([a], [printodd])
 m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
 m4_set_list([a])
 m4_set_add([a], [])
@@ -1158,6 +1213,7 @@ yes
 ,,4
 ,3
 ,1,2,3,,4
+:1:3
 
 2
 
@@ -1221,11 +1277,15 @@ m4_len(m4_set_contents([a]))
 m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
   [m4_set_remove([b], b, [-])])]))
 m4_set_size([b])
+m4_define([prune3x], [m4_if(m4_eval([$1 % 3]), [0],
+  [m4_set_remove([a], [$1], [-])])])dnl
+m4_len(m4_set_map([a], [prune3x]))
 m4_count(m4_shift(m4_set_intersection([a], [b])))
 ]], [[38894
 5000
 5000
-5000
+3333
+3334
 ]])
 
 AT_CLEANUP


hooks/post-receive
--
GNU Autoconf source repository




reply via email to

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