# Bug: Syntax error when using 'or' keyword

**URL:** <https://www.ruby-forum.com/t/bug-syntax-error-when-using-or-keyword/86861>\
**Category:** Ruby\
**Created:** [March 24, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/bug-syntax-error-when-using-or-keyword/86861 "2006-03-24T18:51:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [March 24, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/bug-syntax-error-when-using-or-keyword/86861/1 "2006-03-24T18:51:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [March 24, 2006, 7:23pm UTC](https://www.ruby-forum.com/t/bug-syntax-error-when-using-or-keyword/86861/2 "2006-03-24T19:23:25Z")

</div>

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](http://www.rubypowerandlight.com))

“Ruby for Rails” chapters now available  
from Manning Early Access Program! [Ruby for Rails](http://www.manning.com/books/black)

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [March 24, 2006, 8:06pm UTC](https://www.ruby-forum.com/t/bug-syntax-error-when-using-or-keyword/86861/3 "2006-03-24T20:06:04Z")

</div>

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/ruby-core/7553](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/7553)

– Daniel

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [March 25, 2006, 11:29pm UTC](https://www.ruby-forum.com/t/bug-syntax-error-when-using-or-keyword/86861/4 "2006-03-25T23:29:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![agnathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@agnathan](https://www.ruby-forum.com/u/agnathan)\
**Post date:** [March 25, 2006, 11:00pm UTC](https://www.ruby-forum.com/t/bug-syntax-error-when-using-or-keyword/86861/5 "2006-03-25T23:00:16Z")

</div>

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
