[m4_if([$#], 0, [],
[$#], 1, [],
[$#], 2, [$2],
- m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))],
- [$3])])
+ [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))],
+ [$3])])])
# m4_map(MACRO, LIST)
m4_map([$1], m4_cdr($2))])])
+# m4_map_sep(MACRO, SEPARATOR, LIST)
+# ----------------------------------
+# Invoke MACRO($1), SEPARATOR, MACRO($2), ..., MACRO($N) where $1, $2... $N
+# 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))])])
+
+
## ---------------------------------------- ##
## 6. Enhanced version of some primitives. ##
## ---------------------------------------- ##
# ------------------
# This macro invokes all its arguments (in sequence, of course). It is
# useful for making your macros more structured and readable by dropping
-# unecessary dnl's and have the macros indented properly.
+# unnecessary dnl's and have the macros indented properly.
m4_define([m4_do],
[m4_if($#, 0, [],
$#, 1, [$1],
# Implementing `foreach' loops in m4 is much more tricky than it may
# seem. Actually, the example of a `foreach' loop in the m4
# documentation is wrong: it does not quote the arguments properly,
-# which leads to undesired expansions.
+# which leads to undesirable expansions.
#
# The example in the documentation is:
#
# of brackets around $1 (don't forget that the result must be quoted
# too, hence one more quoting than applications).
#
-# Then notice the 2 last pattens: they are in charge of removing the
+# Then notice the 2 last patterns: they are in charge of removing the
# leading/trailing spaces. Why not just `[^ ]'? Because they are
# applied to doubly quoted strings, i.e. more or less [[STRING]]. So
# if there is a leading space in STRING, then it is the *third*