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
10000.

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.

    print 0+$var

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

/\s*[+-]{0,1}\d[\d.]*(e[+-]\d+)?([+-]{0,1}\d[\d.]*(e[+-]\d+)i)?/

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

--
Glenn
=====
Due to the current economic situation, the light at the
end of the tunnel will be turned off until further notice.


Reply via email to