Front page | perl.perl6.language |
Postings from October 2001
From: Glenn Linderman
October 11, 2001 11:18
Message ID: 3BC5E28B.29F4CB60@netzero.net
Aaron Sherman wrote:
> > It's bothered me that I can write 100_000 in my perl code, but if I have
> > a string "100_000" it'll evaluate to 100 when numerified. It would be
> > really weird if "10indigo" became 10i, "1e3foobar" became 1000, and
> > "10_000" became 10 in Perl 6 IMHO.
Note that in Perl 5.6.1 AS Build 626, that "1e3foobar" already becomes 1000.
I tend to agree, though, that if support for "10i" or "10k" or "10ki" or "10iki"
were added to implicit numeric string conversions that "10_000" should also become
In my proposals for metric suffices, I was mentally proposing them for code
constants (and eval, of course), not implicit string conversions.
On the other hand, there is a case to be made that any form of number that might
get printed by perl's unformatted i.e.
should be reconvertible back to a string via implicit numeric conversions of
strings. I think the only thing that would affect would be imaginary numbers, if
supported, and if enabled in the lexical scope of the conversion. So the full
syntax of the convertible constants would then match the pattern
or something close to that. Note the only "expression" syntax supported in there
is the + or - between the real and imaginary parts, and if that exists, the
trailing i would be required.
> If strings in numeric context are treated the same way as the parser would, then
> I think there need to be warnings for trailing garbage.
It would certainly seem reasonable to have a warning for numeric conversion of
strings containing trailing garbage. At least under some level of strict-ness.
Or, perhaps a collection of string methods could be useful...
$string.as_num # do the Perl usual implicit string conversion
$string.is_num # same as as_num, but undef if trailing garbage
$string.as_code_num # convert all numeric literals legal in code
$string.is_code_num # same as as_ext_num, but undef if garbage
Due to the current economic situation, the light at the
end of the tunnel will be turned off until further notice.