On Aug 19, 1:43 am, Graeme Defty <
graeme.de...@gmail.com> wrote:
> Simple explanation: -2**2 should be -4, not 4
...
> Ruby does it like that ;-)
bc disagrees with you though:
brian@x100:~$ echo "-2^2" | bc
4
brian@x100:~$ echo "-(2^2)" | bc
-4
That's what I would have expected - and ruby surprises me. In C, all
unary operators bind more tightly than any binary operator. (Not that
C has a binary exponentiation operator though)
But if reia is modelled on ruby, I guess it's reasonable to follow
ruby. Probably ruby just follows perl.
> In fact Ruby also makes the unary operators right-associative. I do not
> think that makes any difference, but it makes sense that --2 parses as
> -(-2) and right-associative is better for PEGs so looks worth changing.
Yes, same in C: closest operators apply first. And all right-unaries
before left-unaries, e.g. *x++ is *(x++)