bug-m4
[Top][All Lists]
Advanced

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

[sr #105855] Multi-op patsubst() and translit()


From: Daniel Richard G.
Subject: [sr #105855] Multi-op patsubst() and translit()
Date: Sat, 12 May 2007 01:39:13 +0000
User-agent: Mozilla/5.0 (compatible; Konqueror/3.5; Linux; X11; x86_64; en_US) KHTML/3.5.6 (like Gecko)

Follow-up Comment #2, sr #105855 (project m4):

(typeytype in the new-and-improved translit macro)
=>
translit([abc123], [[a-z]], [[A-Z]], [[0-4]], [[5-9]])
=> ABC678
translit([abc)123], [[a-z]], [[A-Z]], [[0-4]], [[5-9]])
=> /opt/m4/bin/m4:stdin:7: Warning: translit: too few arguments: 1 < 2
ABC123,
     [0-4],[5-9])

Robustness against meta-characters was the issue for me.

I didn't go so far as to try a recursive macro, but there were two other
approaches I was experimenting with. First, iteratively operating on a
temp-variable macro...

pushdef([tmp], [$1])
define([tmp], patsubst(tmp, [pat1], [rep1]))
define([tmp], patsubst(tmp, [pat2], [rep2]))
...
tmp
popdef([tmp])

Second, just nesting the patsubst() calls:

patsubst(patsubst(patsubst([$1], [pat1], [rep1]), [pat2], [rep2]), ...)

The problem with all these approaches is in quoting the text argument to
patsubst. [$1] works perfectly well, but after that, you can't quote the
argument, or the builtin operates directly on macro names ("tmp" or
"patsubst" or "translit").

With a multi-op patsubst()/translit(), [$1] would be all you need. That's my
"real reason" for wanting it, though of course code efficiency and
parallelism to ifelse() figure in there too.

(Oh, by the way, as things currently are, I couldn't even use a recursive
macro. $@ expands to quoted arguments separated by commas---but I'm using a
different argument separator, and this variable doesn't play along.)

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/support/?105855>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

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