Hello,
I fixed m4_cdr. It returned [[]] where it should have returned an
empty list. m4_foreach, which also confused these two, was fixed, too.
These changes could break code which depended on this misbehaviour;
but I don't expect to see this in practice.
See the top of the attached patch for more detailed explanation.
Have a nice day,
Stepan
2005-06-06 Stepan Kasal <[EMAIL PROTECTED]>
m4_cdr of one-member list was [[]] (one-member list containing an
empty string) instead of [] (an empty list. Callers were skewed to
match this misbehaviour. As a consequence of this:
- m4_foreach([x], [], [foo]) expanded to `foo', while
- the expansion of m4_foreach([x], [[]], [foo]) was empty.
I fixed this bug.
* lib/m4sugar/m4sugar.m4 (m4_cdr): If only one argument is given,
expand to an empty string; print error msg if called without
an argument list.
(m4_foreach, m4_map, m4_map_sep): Don't expect the previous
misbehaviour; handle [] and [[]] correctly.
Index: lib/m4sugar/m4sugar.m4
===================================================================
RCS file: /cvsroot/autoconf/autoconf/lib/m4sugar/m4sugar.m4,v
retrieving revision 2.89
diff -u -r2.89 m4sugar.m4
--- lib/m4sugar/m4sugar.m4 24 May 2005 07:25:32 -0000 2.89
+++ lib/m4sugar/m4sugar.m4 1 Jun 2005 09:44:10 -0000
@@ -381,15 +381,25 @@
[$3])])])
+# m4_car(LIST)
+# m4_cdr(LIST)
+# ------------
+# Manipulate m4 lists.
+m4_define([m4_car], [[$1]])
+m4_define([m4_cdr],
+[m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
+ [$#], 1, [],
+ [m4_dquote(m4_shift($@))])])
+
+
# m4_map(MACRO, LIST)
# -------------------
# Invoke MACRO($1), MACRO($2) etc. where $1, $2... are the elements
# of LIST (which can be lists themselves, for multiple arguments MACROs).
m4_define([m4_fst], [$1])
m4_define([m4_map],
-[m4_if([$2], [[]], [],
- [$1(m4_fst($2))[]dnl
-m4_map([$1], m4_cdr($2))])])
+[m4_ifval([$2],
+ [$1(m4_fst($2))[]m4_map([$1], m4_cdr($2))])])
# m4_map_sep(MACRO, SEPARATOR, LIST)
@@ -398,12 +408,8 @@
# are the elements of LIST (which can be lists themselves, for multiple
# arguments MACROs).
m4_define([m4_map_sep],
-[m4_if([$3], [[]], [],
- [$1(m4_fst($3))[]dnl
-m4_if(m4_cdr($3),
- [[]], [],
- [$2])[]dnl
-m4_map_sep([$1], [$2], m4_cdr($3))])])
+[m4_ifval([$3],
+ [$1(m4_fst($3))[]m4_map([$2[]$1], m4_cdr($3))])])
## ---------------------------------------- ##
@@ -680,14 +686,10 @@
m4_define([m4_foreach],
[m4_pushdef([$1])_m4_foreach($@)m4_popdef([$1])])
-# Low level macros used to define m4_foreach.
-m4_define([m4_car], [[$1]])
-m4_define([m4_cdr], [m4_dquote(m4_shift($@))])
m4_define([_m4_foreach],
-[m4_if([$2], [[]], [],
- [m4_define([$1], m4_car($2))$3[]_m4_foreach([$1],
- m4_cdr($2),
- [$3])])])
+[m4_ifval([$2],
+ [m4_define([$1], m4_car($2))$3[]dnl
+_m4_foreach([$1], m4_cdr($2), [$3])])])