TSa Thomas.Sandlass-at-barco.com |Perl 6| wrote:
... Is it defined that non-numeric
strings map to NaN or to zero?
Zero.
But I think in Perl 6 we're leaning more
toward preserving information than Perl 5 did.
This information being the length of the string I presume.
People have been using ++ on strings for decades, and the vocal
complaint is how it increments a file-name part or record field with a
fixed format. It's what people want. Or what they say they want now.
There is another problem with the definition of string increment and
decrement. These operations should be compatible with the corresponding
order ops:
Interesting point. Even with a file part, the expectation is that they
are made "in order".
die unless $x after $y; # generic case shouldn't die
BTW, would 'aaa00' after 'zz99' being true be useful? For the record
if we were to introduce string increment and decrement operators I would
name them mm and pp.
Specifically useful that this one sorts funny? No. But the rules are
generally useful. For anything more complex, you should use a record
type that stringizes to the desired format, but has proper ordering
relations among the record type. Maybe that is a clue to what a
formatting module could be good at. Not for dot-matrix text reports
anymore, but maybe useful for manipulating various fixed-format data.
A similar problem exists with finite types
my int8 ($x, $y) «=« 127;
$x++; # type error or 127 or -128?
die unless $x > $y; # should never die
The original papers on the Self language advocated robust arithmetic
primitives. So that might fail rather than rolling around.
BTW, it will require a new rule in the specification to allow «=« as a
form of pseudo-assignment to declarations. But it has problems with the
list on the RHS anyway. The initializer needs to go =inside= the
signature. I think you meant to write
(my int8 ($x, $y)) «=« 127;
For decrement of unsigned types---which Str essentially is---we
That makes me think of another way to confuse people who don't really
know the difference between numbers and strings:
$x = "-100";
$x++;
say $x; # prints -101, not -99.
could define to stop at the zero element. The case of Bool prescribes
also capping at the top. So all the die conditions above should
incorporate an Inf test to be correct. E.g. A nice idea is to have a
type inf8 that has range -127..126 and -128 and 127 as encodeable
infinities such that
I think int8 is used for controlling the bits in the way people expect
for machine types. But Int8 indeed allows for -127..128 and positive
and negative Inf, and of course for Failures and generic undef.