trans. (T. Onoma) wrote: > On Sunday 10 October 2004 11:28 pm, Jamis Buck wrote: > | No, but if you do: > | > | a = 4.0 > | -a.to_s > | > | You get the same error. When parsing numeric constants, the Ruby parser > | includes '-' as part of the number. When '-' precedes a variable, it > | uses the "-@" operator, which has a lower precendence than ".". > > Thanks, Jamis > > I see. I'm a little surprised that's intended. I understand the precedence of > "." being before the "!" operator, but I would think it would occur right > after "-" and "+" unary operators, user-defined or not. (Maybe "~" too.) Consider this case, then: a = "1.0" -a.to_i What precedence would you expect the '-' to have in this case? I think this would actually be more common than "-a.to_s", too. Still, POLS is in the eye of the beholder. :) > > That's part of the niftiness of what I was offering Markus about his > user-defined operators. One could expect them to have a precedence corollary > to Ruby's built-in operators. True. Though if you are suggesting that people be allowed to change the precedence of existing operators..._that_ might start making me a little uncomfortable. If you change the precedence of an operator, it can change the result of an entire expression, resulting in code breakage, and making it really hard for people to understand what an expression is supposed to be doing. But that's getting us off into the other discussion, which I'd really rather not reignite... - Jamis -- Jamis Buck jgb3 / email.byu.edu http://www.jamisbuck.org/jamis