+2002-03-04 Akim Demaille <akim@epita.fr>
+
+ * doc/autoconf.texi (Evaluation Macros): New.
+ * lib/m4sugar/m4sugar.m4 (m4_lquote): Remove, it is totally
+ useless.
+ (_m4_foreach): Define the variant with immediate evaluation so
+ that it contains exactly the items, not an expression which
+ evaluation is the current item.
+ (m4_re_string, m4_re_word): Don't over quote them.
+
2002-03-04 Akim Demaille <akim@epita.fr>
Instead of having stacking `shift's evaluated at the end, let
Programming in M4sugar
* Redefined M4 Macros:: M4 builtins changed in M4sugar
+* Evaluation Macros:: More quotation and evaluation control
* Forbidden Patterns:: Catching unexpanded macros
Writing Autoconf Macros
@menu
* Redefined M4 Macros:: M4 builtins changed in M4sugar
+* Evaluation Macros:: More quotation and evaluation control
* Forbidden Patterns:: Catching unexpanded macros
@end menu
@end example
@end defmac
+@node Evaluation Macros
+@subsection Evaluation Macros
+
+The following macros give some control over the order of the evaluation
+by adding or removing levels of quotes. They are meant for hard core M4
+programmers.
+
+@defmac m4_dquote (@var{arg1}, ...)
+@msindex dquote
+Return the arguments as a quoted list of quoted arguments.
+@end defmac
+
+@defmac m4_quote (@var{arg1}, ...)
+@msindex quote
+Return the arguments as a single entity, i.e., wrap them into a pair of
+quotes.
+@end defmac
+
+The following example aims at emphasing the difference between (i), not
+using these macros, (ii), using @code{m4_quote}, and (iii), using
+@code{m4_dquote}.
+
+@example
+$ @kbd{cat example.m4}
+# Over quote, so that quotes are visible.
+m4_define([show], [$[]1 = [$1], $[]@@ = [$@@]])
+m4_divert(0)dnl
+show(a, b)
+show(m4_quote(a, b))
+show(m4_dquote(a, b))
+$ @kbd{autom4te -l m4sugar example.m4}
+$1 = a, $@@ = [a],[b]
+$1 = a,b, $@@ = [a,b]
+$1 = [a],[b], $@@ = [[a],[b]]
+@end example
+
+
+
@node Forbidden Patterns
@subsection Forbidden Patterns
# m4_quote(ARGS)
# --------------
-# Return ARGS quoted. Note that a list of quoted arguments is returned,
-# not a quoted list.
+# Return ARGS as a single arguments.
#
# It is important to realize the difference between `m4_quote(exp)' and
# `[exp]': in the first case you obtain the quoted *result* of the
# expansion of EXP, while in the latter you just obtain the string
# `exp'.
m4_define([m4_quote], [[$*]])
-m4_define([m4_lquote], [$@])
-m4_define([m4_dquote], [[$@]])
-
+m4_define([m4_dquote], [[$@]])
# m4_noquote(STRING)
# ------------------
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_define([$1], m4_car($2))$3[]_m4_foreach([$1],
+ m4_cdr($2),
+ [$3])])])
# ------------
# Regexp for `[a-zA-Z_0-9]*'
m4_define([m4_re_string],
-m4_quote(m4_defn([m4_cr_symbols2]))dnl
+m4_defn([m4_cr_symbols2])dnl
[*]dnl
)
# ----------
# Regexp for `[a-zA-Z_][a-zA-Z_0-9]*'
m4_define([m4_re_word],
-m4_quote(m4_defn([m4_cr_symbols1]))dnl
+m4_defn([m4_cr_symbols1])dnl
m4_defn([m4_re_string])dnl
)