Unlike Python, the "word" operators in Ruby aren't logic operators, they're flow control. They way they work is basically a carry-over from the way that Perl handled them. They serve different purposes, and are not equivalent.

On Sat, Feb 24, 2024, 03:24 Information via ruby-talk <ruby-talk@ml.ruby-lang.org> wrote:
Am 19.02.24 um 11:22 schrieb botp:


On Sun, Feb 18, 2024 at 3:05 AM Information via ruby-talk <ruby-talk@ml.ruby-lang.org> wrote:
Hi
p(1 and 2 or 3 and 4)
1. how many brackets do we need?

none if you know the order :)

Maybe there is a misunderstanding:
p(--"--) doesnt work at all (Syntax error)
p((--"--) does the job. (Maybe for this the subject was misleading_
 
2. in my opinion the result should be 2, not 4.
What do you think?

> 1 and 2 or 3 and 4
=> 4

evaluation left to right

> 1 && 2 || 3 && 4
=> 2

evaluation 1st: 1 && 2 => 2
evaluation 2nd: 3 && 4 => 4
evaluation last: 2 || 4

So why should be there another result if using and/or instead of &&/|| ?

(1 and 2 or 3 and 4) != (1 && 2 || 3 && 4)

- That shouldn't be the case!

Andreas

 ______________________________________________
 ruby-talk mailing list -- ruby-talk@ml.ruby-lang.org
 To unsubscribe send an email to ruby-talk-leave@ml.ruby-lang.org
 ruby-talk info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-talk.ml.ruby-lang.org/