Am 08.06.2017 um 01:11 schrieb Zoffix Znet via RT:
Quoting Joachim Durchholz <j...@durchholz.org>:
Actually I'd like to *remove* a special case: That ² is to be interpreted as 2
But it's NOT a special case. You can use any character with No property as a
numeric
literal. That's. The. Entire. Rule that governs the behaviour under examination
in this
ticket.
That cannot be correct. There's that other rule that turns superscripts
into exponents.
There's quite a bunch of these chars:
https://gist.github.com/Whateverable/d94b6a42532a4c1262df794d9be799f3
Yeah I know. Unicode has been around with me for several years now.
² confuses me, does that even make sense?
It's the same as the stated rule above: "Any `No` char can be used as a numeric
literal"
Then this:
²³ confuses me as well.
<Zoffix> m: dd [.unival, .uniprop] with '²'
<camelia> rakudo-moar 0a1008: OUTPUT: «[2, "No"]»
As you can see above, ² is indeed a `No` char, and it's Unicode numeric value
is 2, which is
the numeral you get.
That's pretty much what I've been expecting.
What I don't know is how Rakudo distinguishes ² (superscript/exponent)
from 2 (never assumed to be an exponent). Ideally it would be some
Unicode property, but I do not happen to know whether Unicode already
offers a property for that.
What happens actually is that in ³², the ³ is taken as a base and the
² as an exponent (that's why we're getting ³² == 9.
If the superscripts were handled just like normal literal digits, the
result should be 32.
No, the description above is incorrect and conflates `Nd` Unicode characters
that can be
used as **digits** with `No` chars that can be used as **numerals**. They can't
be used as
individual **digits**. And since Perl 6's expects a term here to be followed by
an op,
there's no ambiguity about what `²` in `³²` is supposed to be interpreted as.
It's an
operator, so we have a `No` numeral followed by an operator; or 3 raised to the
power of 2.
Since we're talking about what Perl *should* do, which means "programmer
expectations", the details of how the parsing is done do not matter
*that* much. Unless, of course, Perl6 is intended to be a language where
parser details are supposed to be part of common knowledge (I do not
think that that's a good idea but I won't pretend I know better than
Perl6 experts about what's the proper gestalt of the language, so I'll
simply agree to disagree and move on).
*If* Perl6 is interpreting superscripts specially (and it already
does)
That statement is incorrect. It doesn't.
It turns ² into an exponent in some contexts, and into a bare number in
others.
That's pretty special when compared how it interprets 2.
since bare exponents do not make any sense
They do. In that context they're a term and you can use ANY `No` character as a
numeral.
I gather that.
It's still unexpected as hell.
And since nobody is going to use that, reviewers on the hunt for
security holes won't have practical experience when they see ³² in a
context that turns ³ into a 3 and ² into an exponent.
E.g. what's 2.³²? Is that 2.0**32, or is it 2.3²? No matter what the
correct answer is, there's no real experience to go by (because People
Don't Do This), so 50% of reviewers will get it wrong.
That's why you don't do "clever tricks" anymore.
I.e. no specialcasing at all beyond what's already there.
There's no special casing. There's just one rule: "you can use `No` characters as
numerals".
Simple. Elegant. Easy to remember.
Except 90% of programmers won't be able to tell a No from an Nd when
they see them in code.