From: Joel VanderWerf Date: 2001-10-27T04:21:54+09:00 Subject: [ruby-talk:23495] Re: Issues with white space [was Re: Bruce Eckel's opinion of Ruby] Sean Russell wrote: > > ts wrote: > > >>>>>> "S" == Sean Russell writes: > > > > S> Raja S. wrote: > >>> puts( ( 8 > >>> + 20) / 2) => 10 > > > > S> This is really, really bizarre. Can anyone explain to me why this is > > true? S> A parse error, I could understand... but 10? > > > > pigeon% ruby -e 'puts((8 ; + 20) / 2)' > > 10 > > pigeon% > .... > > because ruby has seen `;' (or newline) this was interpreted as a block of > > instructions, and the block return the value of the last statement. > > No, I understand this, and it makes sense... why isn't it a parse error? > It doesn't seem like you should be able to drop arbitrary parens in the > source just anywhere you please. IE, > > +20) / 2) > > should produce a parse error, n'est pas? Why, then, should the above code > be interpreted as it is? Parenthesis should have the highest precidence of > any element... don't they? > > --- SER C does something similar: main() { printf("%d\n", (8, + 20) / 2); } The difference is just that, in Ruby, newline is an expression separator, whereas in C it is not. -- Joel VanderWerf California PATH, UC Berkeley mailto:vjoel@path.berkeley.edu Ph. (510) 231-9446 http://www.path.berkeley.edu FAX (510) 231-9512