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


stomar (Marcus Stollsteimer) wrote:

> I refute your primary supposition. In the mathematical expression -2·3, the unary `-' can be interpreted both as a multiplication, (-1)·2·3, and as subtraction, 0 - 2·3. Both interpretations are equally valid. Which one you choose has no effect on the result.
 
It has to be interpreted one way or the other.  This is what operation precedence is for.  This is, for example, how Model Theory deals with formulas without all explicit parentheses.  This is what parsing is in the sense of formal grammar.  I believe that in mathematical language `-2·3` is parsed `(-(2·3))`, as if `0` was taken out of `(0-(2·3))`.

@trans, this is why mathematical notation is not loose, because there is operation precedence taught in elementary school.

> I think there is no sense in discussing or speculating further, as long as you do not provide a citation that confirms your mere **assumption** that the "mathematical parsing rule" (I doubt there is one) is -(a * b). And which one feels more "natural" to you (or to any Ruby user) is no argument at all.

I will think about a reference, it seems that Google doesn't know :).

> And BTW, I do not think anyone of us is really qualified enough in this field to decide on this issue.

What field are you talking about?  I think i am qualified in mathematics, but Ruby is not mathematics, and it is not up to me to decide.  I do not mind learning something new anyway.

----------------------------------------
Bug #7331: Set the precedence of unary `-` equal to the precedence `-`, same for `+`
https://bugs.ruby-lang.org/issues/7331#change-33639

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/