From: hakunin Date: 2008-06-17T13:09:00+09:00 Subject: Re: print(true and true) #=> the parenthesis issue On Jun 16, 10:48 pm, Justin Collins wrote: > hakunin wrote: > > The parenthesis have been discussed before, but maybe this is another > > angle. In a nutshell: > > > print(true and true) # => throws the following: > > > SyntaxError: compile error > > (irb):14: syntax error, unexpected kAND, expecting ')' > > print(true and true) > >               ^ > >    from (irb):14 > > > print (true and true) # => works. (notice the space) > > > It looks obvious that the only parenthesis around the method args are > > containing the expression to be evaluated, so why would this cause > > ambiguity?  Especially strange that the incorrect way - with the space > > - works as expected.  Is there any fix in the works? Anything done > > about this? > > > Thanks! > > print (true and true) is not incorrect, it is just using parentheses for > a different purpose. > > What you are seeing is just a precedence issue, because "and" and "or" > have very low precedence. > > Compare: > > print(true && true) > print(true or true) > print(true || true) > print((true and true)) > print((true or true)) > > Maybe you already knew that, though? > > -Justin That makes sense, and yes, that I realized. In print() parenthesis are enclosing the args, whereas in print () parenthesis are affecting precedence of passed-in expression. However, from the usability perspective, isn't it against some basic nature laws to leave it like this? I would understand if print(true and return) was to be made possible, although it looks quite ugly. In this case - Ruby says "i don't need it, but I won't give it to you either!" - an error occurs, but no reason provided for this to be restricted. If enclosed arguments can only either be replaced with args list, or with a high precedence expression (otherwise error), then why not allow arg- enclosing parenthesis to behave like precedence modifiers as well, so that expression inside them plays first? Overall it seems to be only better for the elegance of code, and wouldn't hurt anyone. Unless I'm missing the rest of the iceberg.