On Tue, 2005-03-15 at 10:09, Autrijus Tang wrote: > Currently Pugs numifies hexadecimal and octal strings as if they > are literals; that means "0x123" and "0o456" all work as expected. > Is that an acceptable treatment? What about "Inf" and "NaN" in > numeric context?
This has long been a point of contention in Perl 5. There are two camps when it comes to how to interpret strings as numbers: 1. You must treat them the same for consistency. 2. You must not treat them the same because someone reading in lines of a report like the following could be seriously shocked by the behavior: $ Book 5foundation 8rama 0xanth The logic goes: why should "8rama" and "0xanth" be treated differently when they are both numbers followed by letters? There's no particularly right answer, IMHO, so why doesn't Perl 6 just go all ways? Have a Perl 5 atof mode, a hard-line mode that throws an exception if handed anything other than a number that would be valid in Perl source and a mode that silently makes assumptions, deletes trailing junk and tries to act "perl6ish". # Untried, likely wrong pseudo-code: use atof::perl5; assert { "0xanth" == 0 }; use atof::strict; try { "0xanth" == 0; CATCH { assert { $@ && $@ ~ /atof/ } } } assert { "0xa" == 0xa } use atof::perl6; # Default? assert { "0xanth" == 0xa } Pardon me if I'm forgetting a document that already decided this. Of course, partly this is better directed at p6l... I wasn't sure if I should move it to that list or not. -- Aaron Sherman <[EMAIL PROTECTED]> Senior Systems Engineer and Toolsmith "It's the sound of a satellite saying, 'get me down!'" -Shriekback