Re: Suggestion to add ifndef builtin macro

Eric Blake <[email protected]> Thu, 15 May 2014 14:29:00 -0600
Newsgroups gmane.comp.gnu.m4.general
Organization Red Hat, Inc.
Message-ID <[email protected]>
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.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc (application/pgp-signature, 604 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Public key at http://people.redhat.com/eblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBCAAGBQJTdSOMAAoJEKeha0olJ0NqV1sH/3i34AmNvQ8S9qmiEThsLFKY
Tcya10526K5BABKe9+COxF1hkPEJIP0WlB7SV5jThisdvNO5eSkDlu9cD0Z3wEcP
xdgHI/r+hJ2qKnjHPcSh5g7HgWPVMn7kqK1Yx5IItMH5s/y05EEM9M7tO4RBu0nX
Vq3G+KJw9eiFvL4y0CrNXNYxiy4ZMVHlRZuVS+FINcfshW/S+bcnLXRzfhuEzfCd
/9LfxXvm9tQYFc9erZRVqPi5XbG6j3UQy14PS7pcZyj3EnsqNBoY4Rdan34avyVP
hTsfoENS+HZgYBAodd4U4+E+xaIy657Q1tnXq+5GuXcqrpkiBVTm99gY8cUThzI=
=7/Ta
-----END PGP SIGNATURE-----