Issue #7331 has been updated by alexeymuranov (Alexey Muranov).


@stomar, as mathematical parsing rules are not and apparently will not be observed in Ruby, i do not understand very well your point of view.

Either a programmer/user knows the operation precedence is Ruby, or not. Unless you want to encourage use of Ruby without understanding how an expression the user writes will be parsed, let us assume that the user is required to know that when he/she writes `-2 * -2`, this actually means `(-2) * (-2)` for Ruby, and will be executed accordingly.

Do you think that remembering in the same time that `-2 ** -2` actually means `-(2 ** (-2))` and not `(-2) ** (-2)` will be easy? Does this parsing
`-2 * -2`  ->  `(-2) * (-2)`
`-2 ** -2` -> `-(2 ** (-2))`
make more mathematical sense than this one
`-2 * -2`  ->  `(-2) * (-2)`
`-2 ** -2` -> `(-2) ** (-2)`
?

To me, it would be easier to remember that Ruby alway implicitly add parentheses around an expression of the form `-a`, than to remember that for some reason  the unary minus in Ruby has higher precedence that the binary one, and that the order of precedence of unary `-` and binary `*` is inverted.

I do not quite understand in what metric the current Ruby parsing is closer to the subset of "mathematically natural ones" than would be the one proposed in #7328, given that the present proposal stays rejected.  :)
----------------------------------------
Bug #7331: Set the precedence of unary `-` equal to the precedence `-`, same for `+`
https://bugs.ruby-lang.org/issues/7331#change-33408

Author: alexeymuranov (Alexey Muranov)
Status: Rejected
Priority: Normal
Assignee: 
Category: core
Target version: 
ruby -v: 1.9.3


=begin
I will not be surprised if this proposal is rejected, because the compatibility would be a mess, but i feel i need to start a discussion.  This continues the discussion in #7328.

To the best of my knowledge, in mathematics the unary minus has the same precedence as the binary one.  However, in the expression

  - a * b

Ruby computes first (({-a})), and then the product.  This means that if i want (for whatever reason) to compute the expression in the natural order, i have to put the parentheses:

  - (a * b)

which looks very strange to me.  I would consider this a bug.
=end



-- 
http://bugs.ruby-lang.org/