<html><div style='background-color:'><DIV> <P><BR><BR></P></DIV> <DIV></DIV> <DIV></DIV>>From: Dave Thomas <DAVE / PRAGMATICPROGRAMMER.COM> <DIV></DIV>>Reply-To: ruby-talk / ruby-lang.org <DIV></DIV>>To: ruby-talk / ruby-lang.org (ruby-talk ML) <DIV></DIV>>Subject: [ruby-talk:19076] Re: a+, a++, a+++, a++++, a+ ---, a + *** <DIV></DIV>>Date: Sat, 4 Aug 2001 00:17:05 +0900 <DIV></DIV>> <DIV></DIV>>"Dat Nguyen" <THUCDAT / HOTMAIL.COM>writes: <DIV></DIV>> <DIV></DIV>> > a = 0 # => 0 <DIV></DIV>> > <DIV></DIV>> > a+ 1 # => 1 <DIV></DIV>> > <DIV></DIV>> > a++ 1 # => 1 <DIV></DIV>> > <DIV></DIV>> > a+++ 1 # => 1 <DIV></DIV>> > <DIV></DIV>> > a+ ++++++ 1 # => 1 <DIV></DIV>> > <DIV></DIV>> > a + --- 3 #=> <DIV></DIV>> > <DIV></DIV>> > a + *** 3 #=> SyntaxError: compile error <DIV></DIV>> > (irb):28: parse error <DIV></DIV>> > <DIV></DIV>> > Why? <DIV></DIV>> <DIV></DIV>>Because '+' is both a unary and a binary operator, and '*' isn't. <DIV></DIV>> <DIV></DIV>>Now, for extra credit, why is this OK <DIV></DIV>> <DIV></DIV> <P>> a+ 1 </P> <P>a.+(1)</P> <DIV></DIV>> <DIV></DIV>>and this isn't: <DIV></DIV>> <DIV></DIV> <P>> a +1</P> <P>sending to the root object the message "a +1" does not fail if the following was defined:</P> <P>def a(b)</P> <P>end</P> <P>but the next question raised. I cannot override the above with:</P> <P>def a(b, c)</P> <P>end</P> <P>and expect:</P> <P>a +1</P> <P>or</P> <P>a 2 3</P> <P>to work. The list of args is different. Why doesn't it work?</P> <P>Regards</P> <P>Dat</P> <DIV></DIV>> <DIV></DIV>>Regards <DIV></DIV>> <DIV></DIV>> <DIV></DIV>>Dave <DIV></DIV></div><br clear=all><hr>Get your FREE download of MSN Explorer at <a href='http://go.msn.com/bql/hmtag_itl_EN.asp'>http://explorer.msn.com</a><br></html>