Difference between "and" and "&&"

Hi sir David [mailto:dblack@candle.superlink.net]:

You wrote:

Yes. The first one is equivalent to:

(haveBoth = a) and b

The second is:

haveBoth = (a && b)

I am surprise and I’m new to Ruby :slight_smile:

I do find both structurally same, but why the difference in precedence?

Pls enlighten…

David

Many thanks,
-botp

[On ‘and’ and ‘&&’]
I am surprise and I’m new to Ruby :slight_smile:

I do find both structurally same, but why the difference in precedence?

Pls enlighten…

Not so long ago, Matz stated that the difference in precedence was because
natural language doesn’t observe a high precedence for ‘and’. I thought that
was a very nice observation from a computer geek.

Anyway, if you get any more authoriatitive answers (I may be confusing the
issue with something else :), this one should be a FAQ.

Cheers,
Gavin

···

From: “Peña, Botp” botp@delmonte-phil.com

Thu, 21 Nov 2002 15:04:59 +0900: Peña, Botp ("Peña, Botp"
botp@delmonte-phil.com):

Hi sir David [mailto:dblack@candle.superlink.net]:

You wrote:

Yes. The first one is equivalent to:

(haveBoth = a) and b

The second is:

haveBoth = (a && b)

I am surprise and I’m new to Ruby :slight_smile:

I do find both structurally same, but why the difference in
precedence?

Pls enlighten…

Remember, if in doubt, you can always add more parenthesis; not only
does it make sure that Ruby (or any language, really) understands what
you want, it also makes sure that you understand what you want. :wink:

I usually do that anyway, to keep myself in check- In any case where i’m
using &&, ||, etc, throw it in a () to make sure my meaning is
understood.

···


< There is a light that shines on the frontier >
< And maybe someday, We’re gonna be there. >
< Rando Christensen / rando@babblica.net >

Hi –

From: “Peña, Botp” botp@delmonte-phil.com

[On ‘and’ and ‘&&’]
I am surprise and I’m new to Ruby :slight_smile:

I do find both structurally same, but why the difference in precedence?

Pls enlighten…

Not so long ago, Matz stated that the difference in precedence was because
natural language doesn’t observe a high precedence for ‘and’. I thought that
was a very nice observation from a computer geek.

Indeed. There does seems to be an unstated (at least in any grammar
book I remember) rule that & binds more tightly than and in English.
It’s interesting that sometimes in TV or film credits you see
something like:

Screenplay by David Black and Gavin Sinclair & Yukihiro Matsumoto

where the & between the latter two mean that they are a writing team.

David

···

On Thu, 21 Nov 2002, Gavin Sinclair wrote:


David Alan Black
home: dblack@candle.superlink.net
work: blackdav@shu.edu
Web: http://pirate.shu.edu/~blackdav