On Tue, Jun 17, 2008 at 9:44 AM, Michael Ulm
<michael.ulm / isis-papyrus.com> wrote:
> 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?
>>
>
> This one really puzzles me. I know of the operator precedence
> hierarchy in Ruby, but this doesn't seem to help me figure
> out why the parser gets confused here. Could someone give
> some insights in the thought process of the parser when it
> encounters "print(true and true)" ?

1. print (true and true)
2. print(true and true)

In the one case the parser first evaluates "true and true" for a
boolean result (true) and
then passes that to print. In the second case the parser seems to be expecting
something like:  print(true) and print "hello"

It seems wrong to me too, since I'd expect the brackets to remove
"print" from the
equation until the bracketed section is evaluated. Perhaps someone can show some
obscure syntax that requires this behavior.


Les