From: "Mauricio Fernández" Date: 2003-03-22T08:05:59+09:00 Subject: Re: Expression results On Sat, Mar 22, 2003 at 07:39:02AM +0900, Hal E. Fulton wrote: > ----- Original Message ----- > From: "Jim Freeze" > To: "ruby-talk ML" > Sent: Friday, March 21, 2003 4:20 PM > Subject: Re: Expression results > > > > > e6 = (1 > > > + 2); > > I don't know why this is 2. > > > > I agree, this is very odd. > > What's going on? Here's my guess. Compare with the following: batsman@tux-chan:/tmp$ expand -t2 r.rb e = ( a=1 b=2 if a > b "foo" else "bar" end) puts e b =(1 2 3) puts b batsman@tux-chan:/tmp$ ruby r.rb r.rb:11: warning: useless use of a literal in void context r.rb:12: warning: useless use of a literal in void context bar 3 I believe that (1 + 2;) is seen as ( 1 # first 'statement' +2; # second 'statement' ) # value of this expression == that returned by the last statement This looks somewhat surprising as one would like to think that parentheses ensure Ruby sees the statement is not finished, but that would break the usage above. Conclusion: parentheses don't ensure that everything inside them is evaluated as a single expression (statement). -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Why use Windows when you can have air conditioning? Why use Windows, when you can leave through the door? -- Konrad Blum