+2005-06-06 Stepan Kasal <kasal@ucw.cz>
+
+ 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.
+
2005-06-06 Stepan Kasal <kasal@ucw.cz>
* lib/autoconf/general.m4 (_AC_INIT_DEFAULTS): Nuke ac_max_here_lines.
[$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)
# 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))])])
## ---------------------------------------- ##
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])])])