From: Marko Schulz Date: 2002-04-15T01:32:44+09:00 Subject: Re: not vs !, and vs && On Sun, Apr 14, 2002 at 08:52:12AM +0900, Guy N. Hurst wrote: > james@rubyxml.com wrote: > > ... > > So, 'and' and '&&' are *not* synonyms that differ only in precedence? > > (Likewise for '!' and 'not' ) > > > > They are synonyms, but one forms a statement, and the other forms an > expression. I took a look at Rubys parse.y and it seemed like there really is a differentiation between arguments, expressions and statements: - Arguments: Many things can be arguments: Simple assignments, array access, method calls and formulas: i = 1 a[10] o.m() 12 + 14 Surprisingly to me, "X && Y" is an argument, while "X and Y" is not. - Expressions: First of all, everything that is an argument, may also be used as an expression. Beyond that some more things can be expressions: return 42 next X and Y So this is where "X and Y", "X or Y" and "not X" come in. - Statements: Again everything that this an expression, may also be used as an statement. An expression such as "1+2" may up a warning "useless use of + in void context" when used with -w in a void context, but it is legal Ruby. Beyond that the following are examples of statements: x,y = 1,2 alias original new_name do_it() if cond?() Because of the distinction between arguments and expressions, "p(X & Y)" is legal, while "p(X and Y)" is not. Also notice that "p((X and Y))" is OK, since it seems to turn the expression into an argument. Is this interpretation of parse.y correct? Why is "X and Y" only allowed as an expression and not as an argument? -- marko schulz