autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix m4_join


From: Eric Blake
Subject: Re: Fix m4_join
Date: Mon, 15 Oct 2007 07:03:56 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Ralf Wildenhues on 10/15/2007 12:15 AM:
>> What did you have in mind?
> 
> Producing a comma-separated list of items; for readability and line
> length limits, the separator should probably be comma plus newline.

# check for underquoting
m4_define([two], [expanded])

# invoking mysep will produce a quoted comma-newline; you can use
# unquoted mysep as the first argument of m4_join.
m4_define([mysep], [[,]m4_newline])

# Convert ARGS into a single quoted comma-separated list; this list can
# then be fed into m4_foreach, where each arg will then be expanded.
m4_join(mysep, [one], [two], [three])
=> one,
=> two,
=> three
m4_foreach([i], m4_join(mysep, [one], [two], [three]), [ i])
=>  one expanded three

Well, that expands two during the foreach loop.  OK, maybe I see what you
were asking - given a sequence of arguments, how do you turn them into a
single argument that m4_foreach can iterate over, without any further
expansion.  m4_dquote does this.  But a bonus, use a comma-newline
separator rather than just plain comma, so that looking at the
intermediate state is readable.  Maybe I should write up a new macro,
m4_make_list(ARGS), which takes multiple arguments, and does just that.

And while I'm at it, I think it is time that I implement a few other macros:

m4_echo(ARGS) - expands to its arguments, each one quoted.  Useful for
situations, like m4_map, where you have to provide a macro name, but don't
need to do any action.

m4_dquote_elt(ARGS) (see dquote_elt in the m4 manual) - expands to an
unquoted list of each argument double-quoted.

m4_count(ARGS) - expands to the count of the number of arguments

With two still defined as above,

m4_echo(one, two, three)
=> one,expanded,three
m4_echo([one], [two], [three])
=> one,two,three
m4_dquote_elt(one, two, three)
=> [one],[expanded],[three]
m4_dquote_elt([one], [two], [three])
=> [one],[two],[three]
m4_make_list(one, two, three)
=> [

m4_dquote(m4_dquote_elt(one, two, three))
=> [[one]],[[expanded]],[[three]]
m4_dquote_elt(m4_dquote(one, two, three))
=> [[one],[expanded],[three]]
m4_count(m4_dquote([one],[two],[three]))
=> 1
m4_count(m4_dquote_elt([one],[two],[three]))
=> 3

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHE2U684KuGfSFAYARAsYjAKDZMv0sK30ttg8vWnwxHemCA0woDwCgkYYX
RDUJ/TDmQ0x8EU0lA4Ky4t8=
=Nvln
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]