Juerd wrote:
+"0x$_" # hex
+"0o$_" # oct
+"0b$_" # bin (does not exist in Perl 5)
This does require that strings numify the same way literals do, but I
think that's a sane approach anyhow. Now that leading 0 no longer means
the number is octal, I can't think of a good reason to keep the contrast
between literal strings numified during compile time and variable
strings during runtime.
I would think that blending the strong pattern matching of Perl6 with
its strong typing makes for a nice subtype system on strings. So we
could have Str[hex], Str[oct] and Str[bin] that can be build from Num
and Int by means of 'as Str[::base]' where ::base chooses the correspondig
pattern to constrain incoming strings and the format for numbers. Or these
are subclasses of Str.
An example:
my Str[hex] $hex = "abc";
say $hex as Int; # prints 2748
$hex = 17;
say $hex; # prints 0x10
Regards
--
TSa (Thomas Sandlaß)