the need for qindir [was: 2.62 AT_SETUP limitations]

Eric Blake <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.bugs,gmane.comp.gnu.m4.general
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Akim Demaille on 4/24/2008 3:20 AM:

[dropping bug-bison, adding m4-discuss]

|> Really, the problem is
|> that there is no way to determine whether $1 is safe to expand, short of
|> expanding $1; thus, if it was not safe, you've already screwed up the
|> state of the m4 parsing.
|
| I always felt m4 lacks an "eval" macro.  Not the one for arithmetics,
| but one which would run m4 on its argument, and return the expansion
| quoted.  This is what tried to do m4_quote/m4_dquote, but it's fragile.
|
| There are really two sort of macros.  Those which really work on the
| text, and you do not want to evaluate the result.  This is where
| regexp, patsubst etc. live.  And there are the regular just-expanding
| macros.

And macros such as substr are practically worthless as is in a harsh
environment - they operate on text and return an unquoted result, which is
almost never what you want if you don't want the result immediately expanded.

|
| For the latter, a usual single-level of quotation is fine.  For the
| former, we need two.  And we have no safe means to go from one model
| to the other, between text-hacking macros and text-expanding macros.
|
| Something like a new primitive "eval and return quoted" would fill
| the gap.
|
| Well, at least that's what I believed years ago :)
|

Yes, m4 has a TODO item about adding the qindir builtin (and which I will
probably do for m4 1.6).  The original request mentioned making it robust
even in the face of unbalanced quotes inside the text, but I don't know if
I can make the m4 machinery do that.  But I can quite easily make it
behave exactly like indir except for the addition of an additional level
of quotes in the output.  Then you will have (in m4sugar quoting):

m4_define([m4_qsubstr], [m4_qindir([m4_substr], $@)])

such that

m4_define([b], [HI])
m4_substr([abc], [1], [1])
=> HI
m4_qsubstr([abc], [1], [1])
=> b

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

Eric Blake             [email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkgQfS0ACgkQ84KuGfSFAYBCIACg2VSyZFfYlLIKLN4z3QThfl87
aIQAoLRZHqhTqWFhnqsQ4QBlu4+e5Ujx
=ZGvN
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.