in the language twilight

ethan on 2003-08-14T08:24:48

It turns out that String::Ruby (see last journal entry) turns out to be harder than expected. The problem is that duplicating Ruby's behaviour will yield something that is definitely not what perl does. For instance the autoincrement on strings. Ruby will do it like this:

print "!!99!!".next ==> !!100!! print "!!ZZ!!".next ==> !!AAA!!

So first I have to think whether that would make sense in Perl, too. And if so, I'd have to implement it which is a fickle work when doing it in C.

Another example is "-0xAA".hex. In Ruby this will result in -170. Perl's numeric.c:Perl_grok_hex doesn't know how to handle the minus so it spits out 0. At least making this behave as in Ruby is easy in XS.

The hex-thing is also a good example that Ruby does in fact do a few things better than Perl. There is no reason why numbers in hexadecimal notation shouldn't be allowed to have a minus prefixed.

A serious problem is "string".intern. In Ruby this returns the symbol corresponding to "string". A Ruby symbol appears to be something that bears some ressemblance to a Perl typeglob (but I might be completely wrong on this) so in String::Ruby I simply return a reference to the symbol-table of the given name. I am quite aware that this does not really make sense in the world of Perl.