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. No special cases. No "unless followed by a superscript char". Just: 
"Any `No` char is good"

There's quite a bunch of these chars: 
https://gist.github.com/Whateverable/d94b6a42532a4c1262df794d9be799f3

So just as you can write:
    
    <Zoffix> m: say ⅓²
    <camelia> rakudo-moar 0a1008: OUTPUT: «0.111111␤»

You can write:

     <Zoffix> m: say ²²
     <camelia> rakudo-moar 0a1008: OUTPUT: «4␤»

In BOTH of these cases a No numeral is used with a ² "postfix n" operator.
Entirely identical. No special casing.

> But before deciding how to deal with them: What are the 
> supposed/expected meaning of the following constructs?
>   3²
>   x²
>   ²

>   3² should be 3 squared, i.e. 9
Indeed that is it. Same as in regular mathematics. The 3 raised to power 2:

    <Zoffix> m: say 3²
    <camelia> rakudo-moar 0a1008: OUTPUT: «9␤»

>   x² to be x squared, i.e. an expression
Indeed that is it. Same as in regular mathematics. `x` raised to power 2:

    <Zoffix> m: my \x = 42; say x²
    <camelia> rakudo-moar 0a1008: OUTPUT: «1764␤»

>   ²  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"

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

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

> *If* Perl6 is interpreting superscripts specially (and it already 
> does)

That statement is incorrect. It doesn't.

>, *then* I expect it to recognize a bare ² as an exponent
That's incorrect, because it expects a term in that position, not an operator.

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

Reply via email to