[Top][All Lists]

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

Re: m4_map and AC_REQUIRE hoisting

From: Nick Bowler
Subject: Re: m4_map and AC_REQUIRE hoisting
Date: Wed, 24 Jan 2018 11:28:20 -0500

Hi Eric,

On 1/24/18, Eric Blake <address@hidden> wrote:
> On 01/24/2018 12:32 AM, Nick Bowler wrote:
>> Hello Autoconfers,
>> I hit a weird (to me) issue involving m4_map(all) and AC_REQUIRE, and I
>> would appreciate some help understanding what's going on here!
> Let's see if I can give an explanation.

Thanks for the explanation.  Indeed, when thinking about this more (and
not at 01:00) I recalled these two tidbits from the autoconf manual:

  - "some of the topological sorting algorithms used in resolving macro
    dependencies use diversions", and

  - "it is important to be aware of an M4 limitation regarding
    diversions: text only goes to a diversion if it is not part of
    argument collection"

which sure enough suggests an underquoting issue that you point out,
and removing some quotes from my "working" examples produces the same
"unexpected" output.

[snip TEST0 bits]
>> But when my macro is using m4_map or m4_mapall, this mechanism seems to
>> break down.  Example:
>>   AC_INIT([test], [0])
>>   AC_DEFUN([DEF1], [echo def1])
>>   AC_DEFUN([TEST1], [m4_mapall([m4_newline], [[echo hello], [REQ1]])])
> Underquoted; the second argument to m4_mapall() is a "comma-separated
> quoted list of argument descriptions" which are "in turn a
> comma-separated quoted list of quoted elements".  Better would be:
> m4_mapall([m4_newline], [[[echo hello]], [[REQ1]]])

I see.  Indeed this is all spelled out clearly in the manual and despite
rechecking this many times I failed to actually understand what m4_map
is expecting for its 2nd argument.

I think the fact that m4_map could pass anything other than one argument
to the "mapped" macro did not even enter my head as a possibility, and
the examples presented even demonstrate this usage!

[snip helpful explanation]
>>   m4_define([my_mapall], [m4_ifval([$2],
>>     [m4_indir([$1], m4_car($2))[]my_mapall([$1], m4_cdr($2))])])
>>   AC_DEFUN([TEST2], [my_mapall([m4_newline], [[echo hello], [REQ2]])])
> Your naive version is less susceptible to underquoting issues [...]

I think the important thing here is that my version always passes
exactly one argument to the "mapped" macro, so it isn't the same
operation as m4_mapall and explains the key difference in results!

That is, it reflects what I /imagined/ m4_mapall does rather than what
it /actually/ does... :)

> Hopefully my explanation into the deep magic guts helped!



reply via email to

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