[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: m4_quote [was: fix AT_SETUP's sh-escaping]
From: |
Joel E. Denny |
Subject: |
Re: m4_quote [was: fix AT_SETUP's sh-escaping] |
Date: |
Thu, 26 Oct 2006 02:14:53 -0400 (EDT) |
On Wed, 25 Oct 2006, Eric Blake wrote:
> It exists for expanding relatively arbitrary parameters inside nested
> macros. For example, in the upcoming M4 1.4.8 manual, I have the
> following example of a foreach macro (converted here to m4sugar syntax):
>
> # foreachq(x, `item_1, item_2, ..., item_n', stmt)
> # quoted list, simple version
> m4_define([foreachq], [m4_pushdef([$1])_foreachq($@)m4_popdef([$1])])
> m4_define([_arg1], [$1])
> m4_define([_foreachq], [m4_if(m4_quote($2), [], [],
> [m4_define([$1], [_arg1($2)])$3[]$0([$1], [m4_shift($2)], [$3])])])
>
> If you don't use m4_quote, then the unquoted expansion of $2 inside the
> first argument of m4_if will lead to syntax errors if $2 contains unquoted
> commas.
Thanks, that clears up my confusion. Also, it really helps me to see why
[$2] isn't equivalent to m4_quote($2). The autoconf manual's example in
section "8.3.3 Evaluation Macros" doesn't draw a distinction between the
two:
$ cat example.m4
# Overquote, so that quotes are visible.
m4_define([show], [$[]1 = [$1], $[]@ = address@hidden)
m4_divert(0)dnl
show(a, b)
show(m4_quote(a, b))
show(m4_dquote(a, b))
$ autom4te -l m4sugar example.m4
$1 = a, $@ = [a],[b]
$1 = a,b, $@ = [a,b]
$1 = [a],[b], $@ = [[a],[b]]
I just did this experiment, which for me is clearer than either above
example:
$ cat example.m4
m4_divert(0)dnl
m4_define([mkargs],[1,2,3])
m4_define([echo_arg1],[[$1]])
echo_arg1(mkargs)
echo_arg1([mkargs])
echo_arg1(m4_quote(mkargs))
echo_arg1(m4_dquote(mkargs))
$ autom4te -l m4sugar example.m4
1
mkargs
1,2,3
[1],[2],[3]
I wonder if this could be added to the autoconf manual.
- Re: fix AT_SETUP's sh-escaping, Joel E. Denny, 2006/10/22
- Message not available
- Message not available
- Re: fix AT_SETUP's sh-escaping, Paul Eggert, 2006/10/23
- Re: fix AT_SETUP's sh-escaping, Joel E. Denny, 2006/10/25
- m4_quote [was: fix AT_SETUP's sh-escaping], Eric Blake, 2006/10/25
- Re: m4_quote [was: fix AT_SETUP's sh-escaping],
Joel E. Denny <=
- Re: m4_quote [was: fix AT_SETUP's sh-escaping], Eric Blake, 2006/10/26
- Re: m4_quote, Paul Eggert, 2006/10/26
- Re: m4_quote, Joel E. Denny, 2006/10/26
- Re: m4_quote, Eric Blake, 2006/10/26
- Re: fix AT_SETUP's sh-escaping, Stepan Kasal, 2006/10/25
- Re: fix AT_SETUP's sh-escaping, Paul Eggert, 2006/10/25
- Re: fix AT_SETUP's sh-escaping, Joel E. Denny, 2006/10/26
- Re: fix AT_SETUP's sh-escaping, Stepan Kasal, 2006/10/26
- Re: fix AT_SETUP's sh-escaping, Joel E. Denny, 2006/10/26
- Re: fix AT_SETUP's sh-escaping, Eric Blake, 2006/10/26