[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: listing currently defined macros
From: |
Eric Blake |
Subject: |
Re: listing currently defined macros |
Date: |
Mon, 18 Feb 2008 11:19:51 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Gary V. Vaughan on 2/17/2008 2:07 AM:
Hi Gary, and thanks for a review of my ideas, plus some cool ones of your own.
|
| However (breaking my own rule about not introducing additional macros if
| at all possible), I think list sorting and filtering are both useful enough
| idioms that we should break them out into new builtins so that our users
| needn't resort to the hackish things you mention below... which merely
| highlight deficiencys in the current language implementation. Also,
| m4symbols proper will be faster in the case where the order of returned
| symbols is not important. So:
|
| -- Builtin (gnu): m4symbols([NAMES...])
| With no arguments, `m4symbols' expands to a unordered, comma-separated
| list of the names of all currently defined macro. Each macro name is
| quoted.
In other m4 implementations (I tested Solaris and OpenBSD), dumpdef output
is also unordered - it is only ordered on GNU. But I would be okay with a
documented change to dumpdef behavior to be unordered, particularly since
we could then do:
define(`dumpdef', `builtin(`dumpdef', sort(m4symbols))')
to recover the former behavior.
| -- Builtin (list): sort(NAME, [...])
| Expands to a sorted, comma-separated list of quoted NAME arguments.
| This macro was added in M4 2.0.
|
At which point, the user can easily create:
define(`cmp', `ifelse(`$1', `$2', `0',
~ (sort(`$1', `$2')), `($1,$2)', `-1',
~ `1')')
|
| -- Builtin (list): uniq(NAME, [...])
| Expands to an unordered, comma-separated list of quoted NAME
| arguments,
| with only the first occurrence of duplicate consecutive parameters
| listed in the expansion. This macro was added in M4 2.0.
|
| uniq(m4symbols(`ifndef', `ifdef', `define', `define', `ifdef',
| `undef'))
| =>ifdef,define,ifdef
Don't you mean
~ =>ifndef,define,ifdef
| -- Builtin (list): filter(PATTERN, LIST, [PATSYNTAX])
| Expands to an unordered, comma-separated list of quoted LIST elements
| that match PATTERN, either according to the current RESYNTAX (*note
| Changeresyntax::) or PATSYNTAX if passed.
|
| define(`dquote', ``$@'')
| =>
| sort(filter(`*def*', dquote(m4symbols), `GLOB'))
| =>define,defn,dumpdef,ifdef,popdef,pushdef,undefine
Hmm. This would be the first builtin that takes a quoted list of
elements. Maybe it would be worth also making dquote builtin:
- -- Builtin (list): dquote(ELEMENT, ...)
~ Expand to a quoted, comma-separated list of quoted list ELEMENTs.
so that you could use dquote regardless of the current quoting characters
(in your example, it would only work with `'). Then again, dquote is easy
to implement efficiently without needing another builtin, unlike filter
(which can be implemented, but requires a foreach loop).
| I'm sure we can implement several of the m4sugar style list mangling macros
| eventually, hence I've put these new builtins into a separate list module.
Sounds like a good idea to me. I'll see if I can get some time to write
up such a module.
|> So maybe you could argue that we already have
|> globbing if you can just translate the pattern correctly).
|
| I think this proposal has that covered.
I like the idea of using 'GLOB' as another regex syntax, although it
implies some intelligence in the underlying regex builtins (either we
would do glob->regex translation ourselves, or we would have to decide
between re_search vs. fnmatch).
- --
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
iD8DBQFHucxH84KuGfSFAYARAg/sAJ0Ykcv8P1j71/hCiIiLdd1OSwC0awCfZ+3h
XaAVBMxFHZmtL3vku0OUT+s=
=qm5A
-----END PGP SIGNATURE-----