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.
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-03-24 18: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
1fba4539b6cafe2e60a2916fa184fc2f?d=identicon&s=25 unknown (Guest)
on 2006-03-24 19:23
(Received via mailing list)
Hi --

On Sat, 25 Mar 2006, Daniel Harple 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 (dblack@wobblini.net)
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
9358cc96c46055cd68d4a76a9aefe026?d=identicon&s=25 Daniel Harple (Guest)
on 2006-03-24 20:06
(Received via mailing list)
On Mar 24, 2006, at 7:22 PM, dblack@wobblini.net 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
A402df36168b81b31c17adcbb5ae8cf4?d=identicon&s=25 Pistos Christou (pistos)
on 2006-03-25 23: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
37a3c73ffbf864e4b28f7f2384ee12ce?d=identicon&s=25 Timothy Hunter (tim-hunter)
on 2006-03-25 23:29
(Received via mailing list)
Pistos Christou 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.