Forum: Ruby Bug: Syntax error when using 'or' keyword

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniel H. (Guest)
on 2006-03-24 19:51
(Received via mailing list)
I am getting a parse error when using the 'or' keyword. I do not get
this error with '||'.

$ ruby -v
ruby 1.8.4 (2005-12-24) [powerpc-darwin8.3.0]

$ ruby-yarv -v
ruby 2.0.0 (Base: Ruby 1.9.0 2006-02-14) [powerpc-darwin8.5.0]
YARVCore 0.4.0 Rev: 482 (2006-03-08) [opts: ]

def example(arg)
end

example(nil || 3) # -> no error
example(nil or 3) # -> parse error, unexpected kOR, expecting ')'

-- Daniel
unknown (Guest)
on 2006-03-24 20:23
(Received via mailing list)
Hi --

On Sat, 25 Mar 2006, Daniel H. wrote:

> def example(arg)
> end
>
> example(nil || 3) # -> no error
> example(nil or 3) # -> parse error, unexpected kOR, expecting ')'

There was a thread about this recently on ruby-core.  Matz summed up
the situation as follows:

   OK.  Keyword logical operators (and, or, not) are far lower
precedence
   than comma, even lower than method calls without argument parentheses
   (in parser, they are called as commands), so that they are not
allowed
   be a part of argument expression.


David

--
David A. Black (removed_email_address@domain.invalid)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black
Daniel H. (Guest)
on 2006-03-24 21:06
(Received via mailing list)
On Mar 24, 2006, at 7:22 PM, removed_email_address@domain.invalid wrote:

> There was a thread about this recently on ruby-core.  Matz summed up
> the situation as follows:
>
>   OK.  Keyword logical operators (and, or, not) are far lower
> precedence
>   than comma, even lower than method calls without argument
> parentheses
>   (in parser, they are called as commands), so that they are not
> allowed
>   be a part of argument expression.

Thanks, I should have checked ruby-core archives before posting.

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/...

-- Daniel
Pistos C. (Guest)
on 2006-03-26 00:00
unknown wrote:
>    OK.  Keyword logical operators (and, or, not) are far lower
> precedence
>    than comma, even lower than method calls without argument parentheses
>    (in parser, they are called as commands), so that they are not
> allowed
>    be a part of argument expression.

Is there documentation anywhere which describes when to use the English
words versus the symbols, and why?  All I know is that the words have
far lower precedence, but up to this point, I have been using them in
favour of the symbols whenever possible, using parentheses to force
evaluation order.

More and more, though, I feel "discriminated against" by the language,
in that I should always be using the symbols.

Pistos
Timothy H. (Guest)
on 2006-03-26 00:29
(Received via mailing list)
Pistos C. wrote:
> Pistos
>

The "Expressions" section in Chapter 22 of the Pickaxe, 2nd. ed.,
contains a table of the Ruby operators in precedence order and, in the
"Boolean Expressions" section, some prose that explains the and, &&, or,
||, not and !, and defined? operators.
This topic is locked and can not be replied to.