m4-discuss
[Top][All Lists]
Advanced

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

Re: improve substr


From: Eric Blake
Subject: Re: improve substr
Date: Wed, 24 Dec 2008 21:46:58 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.18) Gecko/20081105 Thunderbird/2.0.0.18 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Jack Woehr on 12/24/2008 7:14 PM:
> Eric Blake wrote:
>> Again, implementing this natively will be more efficient.  What do you
>> think of adding these two enhancements to substr?
>>   
> I think anything you want to do is okay as long as it is a perfect
> superset of the existing behavior. m4 goes back to the mid-1970's
> and we shouldn't break existing code. Especially not mine! :)

It's doubtful that any portable m4 scripts were relying on traditional
behavior, where letting either argument be negative resulted in an empty
output from substr (given that BSD m4 segfaults in that case).  But just
in case you really did rely on that behavior, my proposed semantics are
easy to wrap in a backwards-compatible manner (and yes, I would document
this in the manual as part of the change):

define(`substr',
  `ifelse(eval($2 < 0 || $3-0 < 0), 1, `',
          `builtin(`substr',$@)')')

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

Eric Blake             address@hidden
-----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

iEYEARECAAYFAklTEEIACgkQ84KuGfSFAYC21QCfWsLTH2hb0yCadg+TvKwiwn6y
leIAnj8FIw0kg6hAmmwK8b2lQlAlpRja
=0LgS
-----END PGP SIGNATURE-----




reply via email to

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