m4-discuss
[Top][All Lists]
Advanced

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

Re: Suggestion to add ifndef builtin macro


From: Daniel Goldman
Subject: Re: Suggestion to add ifndef builtin macro
Date: Sat, 17 May 2014 12:46:57 -0700
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

Eric,

> We intentionally want a minimal set of builtins, and leave the
> bulk of the power in wrappers around the builtins.

Thanks for responding. Of course it's a good point to limit the number of builtins. Related to that, is there a reason why incr and decr are builtin macros, when it seems likely they could work as composites, or just use eval directly?

> Yes, and that's why the autoconf language has an m4_ifndef wrapper
> alongside the m4_ifdef wrapper.  But that didn't require a new builtin.
>

Of course, I never suggested a new builtin was required. As I mentioned, I had seen references to ifndef, so I already divined that it existed. The problem was my searches found zero documentation. I'm sure it's there, but it's at least somewhat hidden. All I found was very specialized autoconf macros. Is there a link you (or someone else) could send to autoconf ifndef documentation, along with other general (not specialized) macros used by autoconf?

Finally, the m4 manual has some 25 composite macros. Most of them seem pretty useful. But it's certainly not a comprehensive list (eg, ifndef is not included). Besides the manual, is there any other collection of general purpose m4 composite macros?

Daniel

there might be a collection of composite macros, as used by autoconf or other systems that use m4? Thanks

On 5/15/2014 1:29 PM, Eric Blake wrote:
On 05/15/2014 02:13 PM, Daniel Goldman wrote:
Hi,

I would like to suggest the small change to add an m4_ifndef builtin
macro to some future version of m4.

Why? You can already write your own m4_ifndef macro that wraps the
builtin.  We intentionally want a minimal set of builtins, and leave the
bulk of the power in wrappers around the builtins.

m4_define(`m4_ifndef', `m4_ifdef(`$1', `$3', `$2')')

Reason #1 I suggest adding m4_ifndef is for better communication, to
make the language easier to express the logic. Perhaps a lot of m4 usage
is obscure, but I don't consider that a virtue. I would argue that:

m4_ifndef(`MACRO_1', `MACRO_1' NOT defined)

is clearer than:

m4_ifdef(`MACRO_1', , `MACRO_1' NOT defined)

Yes, and that's why the autoconf language has an m4_ifndef wrapper
alongside the m4_ifdef wrapper.  But that didn't require a new builtin.

Reason #1 in favor of NOT adding is because m4_ifdef is adequate to do
the logical operations. To my understanding the following two macros are
100% equivalent:

m4_ifdef(`MACRO_1', `MACRO_1' defined, `MACRO_1' NOT defined)
m4_ifndef(`MACRO_1', `MACRO_1' NOT defined, `MACRO_1' defined)


Yes, if you write your m4_ifndef wrapper as above.


$ cat ifndef-02.m4
m4_define(`m4_ifndef', `m4_ifdef(`$1', `$3', `$2')')

Yep, you already wrote the correct composite macro.




reply via email to

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