[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Binary Logic, Bug or Feature?

Yukihiro Matsumoto

11/28/2007 4:37:00 AM

Hi,

In message "Re: Binary Logic, Bug or Feature?"
on Wed, 28 Nov 2007 13:33:36 +0900, "Malcolm Lockyer" <maxpenguin@gmail.com> writes:

|I have been pulling my hair out for the last 20 minutes trying to find
|out what is wrong in my app that has some pretty basic binary logic.
|Here is a concise example in an irb session that shows my problem
|(certainly, what I was working on wasn't nearly as simple the sides of
|AND were variables etc.):
|
|?> x = true and true
|=> true
|>> x
|=> true
|
|(this is what I expect, true and true = true)
|
|>> x = true and false
|=> false
|>> x
|=> true
|
|But what I've got here is "true and false" == false, but it assigns
|true to x. So true and false == false, but really == true... Have I
|lost my mind, should it do this? Does it do it for anyone else? It
|seems weird to me since the first example does what I expect, but the
|second doesn't...

Precedence.

x = true and false

is parsed as

(x = true) and false

not

x = (true and false)

matz.

1 Answer

Malcolm Lockyer

11/28/2007 4:58:00 AM

0

On Nov 28, 2007 5:37 PM, Yukihiro Matsumoto <matz@ruby-lang.org> wrote:
>
> Precedence.
>
> x = true and false
>
> is parsed as
>
> (x = true) and false
>
> not
>
> x = (true and false)
>
> matz.
>
>

Of course, that makes perfect sense - I guess I am still getting used to
Ruby's awesome level of flexibility!

Thanks a lot for the quick reply matz, btw - big fan of your work :).


Also, thanks Christian - I will make use of the && in the future!


Thanks,
Malcolm.