-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Daniel Richard G. on 5/19/2007 7:00 PM: > Hello, > > I've been messing around with diversions inside macros, and have come upon > an odd scenario. I'd like to call it a bug, but I get the same behavior > from m4 1.4 as from 1.9a.
Not a bug in m4, but a lack of understanding on your part. You may find using the debug and tracing abilities of m4 useful here. > So, what's going on here, and is there any way to make div10() work as > expected without needing to quote the argument to foo()? > > define(`div10', `divert(10)$1`'divert(0)')dnl > define(`foo', `<FOO>$1</FOO> > ')dnl > dnl > div10(`This is text in div 10. > ')dnl > foo(`This goes inside FOO tags.div10(`This is some more text in div 10. > ')')dnl > foo(This also goes inside FOO tags.div10(`This is even more text in div 10. > '))dnl Or more simply: foo(text1.div10(`text2'))dnl ^ When m4 gets to the point marked by ^, it notices a macro, and expands it to text as it continues to collect the arguments of foo, resulting in: foo(text1.divert(10)text2`'divert(0))dnl ^ but there are still unexpanded macros, so it continues to expand text, further resulting in: foo(text1.text2)dnl ^ that is, you both swapped to and back from diversion 10, all while collecting the argument for foo. Finally, with the argument now in place, foo is invoked, as though it had been called with `text1.text2' as its properly quoted argument. As for how to do this, I recommend that you stick with consistent quoting, as you already surmised. The autoconf manual, and my recent revisions to the m4 manual, are serious when they say that the policy of a consistent interface of one level of quoting per level of parentheses is the easiest way to have predictable results. - -- Don't work too hard, make some time for fun as well! Eric Blake [EMAIL PROTECTED] -----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 iD8DBQFGT76684KuGfSFAYARAk7/AKDLHB4jSR5v0zr40xYq/X3J07noTQCgkeaD tabbF9pj0+JHd5mqbsbuyns= =AgTJ -----END PGP SIGNATURE----- _______________________________________________ M4-discuss mailing list M4-discuss@gnu.org http://lists.gnu.org/mailman/listinfo/m4-discuss