From: botp on
On Thu, Dec 31, 2009 at 10:24 AM, Albert Schlef <albertschlef(a)gmail.com> wrote:
> Why? I thought the only diference between "or" and "||" is the
> precedence.

yes, so you can do eg

>> system "pwd" or raise "no command here"
/home/botp
=> true

>> system "asdf" or raise "no command here"
RuntimeError: no command here

if you know perl, this is no surprise..

as always, there are many ways in ruby, you can use || or the double
parens override.

happy holiday and best regards
-botp

From: Albert Schlef on
botp wrote:
> On Thu, Dec 31, 2009 at 10:24 AM, Albert Schlef <albertschlef(a)gmail.com>
> wrote:
>> Why? I thought the only diference between "or" and "||" is the
>> precedence.
>
> yes, so you can do eg
>
>>> system "pwd" or raise "no command here"
> /home/botp
> => true
>
>>> system "asdf" or raise "no command here"
> RuntimeError: no command here
>
> if you know perl, this is no surprise..


It *is* a surprise. In Perl, unlike in Ruby, `func(0 or 1)` *does*
work....


>
> as always, there are many ways in ruby, you can use || or the double
> parens override.


Well. it turns out there aren't that many ways in ruby.

I originally tried to do the following:

some_func(ARGV[0] or raise "You must provide an argument")

I wish it worked. But it doesn't. So I changed it to:

some_func(ARGV[0] || raise "You must provide an argument")

It still didn't work. So finally I did:

some_func(ARGV[0] || (raise "You must provide an argument"))

It works. But, I must say, it isn't as beautiful as my original plan. It
doesn't read as English.
--
Posted via http://www.ruby-forum.com/.

From: Albert Schlef on
Albert Schlef wrote:
> Well. it turns out there aren't that many ways in ruby.
>
> I originally tried to do the following:
>
> some_func(ARGV[0] or raise "You must provide an argument")
>
> I wish it worked. But it doesn't. So I changed it to:
>
> some_func(ARGV[0] || raise "You must provide an argument")
>
> It still didn't work. So finally I did:
>
> some_func(ARGV[0] || (raise "You must provide an argument"))
>
> It works. But, I must say, it isn't as beautiful as my original plan. It
> doesn't read as English.

Hey, I now see that this works:

some_func((ARGV[0] or raise "You must provide an argument"))

Great. On the other hand, I won't be able to remember this the next time
I need it.
--
Posted via http://www.ruby-forum.com/.

From: Seebs on
On 2009-12-31, Albert Schlef <albertschlef(a)gmail.com> wrote:
> So it seems Ruby internally recognizes some structures as "statemenets"
> and others as "expressions". It seems disapointing at first, but since
> Ruby supports precedence for operators (something Lisp doesn't), there
> has to be some price to pay.

I don't think that's it at all. I think it's that methodname( is a method
call (), not a grouping (). Thus the difference between
puts(a or b)
and
puts (a or b)

In short, it's nothing to do with statements-vs-expressions, and everything
to do with disambiguating method calls vs. parenthesized expressions.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet-nospam(a)seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
From: Albert Schlef on
Seebs wrote:
> On 2009-12-31, Albert Schlef <albertschlef(a)gmail.com> wrote:
>> So it seems Ruby internally recognizes some structures as "statemenets"
>> and others as "expressions". It seems disapointing at first, but since
>> Ruby supports precedence for operators (something Lisp doesn't), there
>> has to be some price to pay.
>
> I don't think that's it at all. I think it's that methodname( is a
> method
> call (), not a grouping (). Thus the difference between
> puts(a or b)
> and
> puts (a or b)
>
> In short, it's nothing to do with statements-vs-expressions, and
> everything
> to do with disambiguating method calls vs. parenthesized expressions.

Interesting.

Why is the following a syntax error?

puts (123 if true)

and the following isn't?

puts (123 or 456)
--
Posted via http://www.ruby-forum.com/.