BUG? or inside argument list

  • Thread starter Kristof Bastiaensen
  • Start date
K

Kristof Bastiaensen

Hi,

I get a syntax error when I try to use "or" inside a argument
list:

#doesn't work:
puts(nil or "string")
String.new(nil or "string")

#the following works:
puts (nil or "string")
String.new((nil or "string"))

It appears that Ruby accepts the "or" when it parses it as an
expression, but not when it parses it as an argument list.
Isn't any expression valid inside an argument list?

$ ruby --version
ruby 1.8.2 (2004-07-16) [i386-linux]

Regards,
KB
 
L

Lennon Day-Reynolds

Kristof,

You can use the '||' operator instead of 'or' in argumet lists:

puts(nil || "string")
String.new(nil || "string")

Hi,

I get a syntax error when I try to use "or" inside a argument
list:

#doesn't work:
puts(nil or "string")
String.new(nil or "string")

#the following works:
puts (nil or "string")
String.new((nil or "string"))

It appears that Ruby accepts the "or" when it parses it as an
expression, but not when it parses it as an argument list.
Isn't any expression valid inside an argument list?

$ ruby --version
ruby 1.8.2 (2004-07-16) [i386-linux]

Regards,
KB
 
K

Kristof Bastiaensen

Kristof,

You can use the '||' operator instead of 'or' in argumet lists:

puts(nil || "string")
String.new(nil || "string")

Yes, I found out that '||' works, but I prefer "or" because it looks
better. I find that the english words express better the meaning than
symbols. If I am correct the english versions and symbol versions are a
bit different (preference rules or something), but it is strange that they
aren't allowed inside an argument list. Is there a reason why this
is so, or is it just a bug?

Thanks,
KB
 
M

Mark Hubbart

Yes, I found out that '||' works, but I prefer "or" because it looks
better. I find that the english words express better the meaning than
symbols. If I am correct the english versions and symbol versions are
a
bit different (preference rules or something), but it is strange that
they
aren't allowed inside an argument list. Is there a reason why this
is so, or is it just a bug?

I have to say, it seems odd to me, to... perhaps it's an unintentional
limitation in the parser? And I agree about the "or" vs "||" thing...
whenever I have the choice, I prefer "or". it's easier to type, and it
looks nicer.

cheers,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,408
Latest member
AlenaRay88

Latest Threads

Top