From: raja@... (Raja S.) Date: 2001-10-26T23:12:38+09:00 Subject: [ruby-talk:23453] Re: Issues with white space [was Re: Bruce Eckel's opinion of Ruby] >> puts( ( 8 >> + 20)/2) => 10 > This is really, really bizarre. Can anyone explain to me why this is > true? A parse error, I could understand... but 10? Ah. Bizarreness is in the eye of the beholder ;-) As I've always felt, everything is intuitive once you understand it ;-) It all boils down to: you can't discard your semi-colon and have it too! Recall that Ruby is line oriented. Once it has got what -it- thinks is a complete ruby expression it executes it. When ruby reads the first line of the below: ( 8 + 20) it gets a complete expression viz., 8 and evaluates it. The second line is treated as +20 (unary +) and hence the whole expression evaluates to 20. The above is equivalent to ( 8 ; + 20) => 20. It is a coincidence that '+' has both a unary and binary interpretation. If multiplication had been used: ( 8 * 20 ) a syntax error would have been flagged. It is interesting that programming languages started out line oriented (Fortran with its continuation column) moved to free form (Algol ...) and now seem to be coming back full circle to line oriented layout again (Python, Tcl, Ruby). But it is very much to the credit of the genius of Matz that Ruby is pretty smart. Unlike Python, Ruby has some ability to automatically detect when an expression is spanning multiple lines: 1 + 2 + # sees a plus and correctly assumes the expression is 3 => 6 # not yet over; smart parsing ! no need for explicit # continuation 1 + 2 # presumes the expression is over + 3 # this is an entirely different line of code 1 + 2 \ # we explicitly say the expression is not yet over. + 3 # the only option we have in Python IIRC So it boils down to: you can't discard the statement terminating semi-colon and still expect its behavior. A design trade-off. Regards, Raja