Professor,
What does if ((x=2)) 2 mean?
Thanks,
Robert

Peter Dalgaard <p.dalgaard@biostat.ku.dk> wrote:
Prof Brian Ripley writes:

> Please do read the posting guide.
> The answer to your question can be found by help("<-") or help("=").
> 
> The '<-' can be used anywhere, but the '=' is
> only allowed at the top level (that is, in the complete expression
> typed by the user) or as one of the subexpressions in a braced
> list of expressions.
> 
> If you don't fully understand that, just use <- always.

The text is not completely accurate though:

> if ((x=2)) 2
[1] 2
> x
[1] 2
> if (x=2) 2
Error: syntax error in "if(x="
> if(x<-2) 2
[1] 2
> if(x < -2) 2
>

We do allow "=" inside parentheses too, it's only in function
arguments (where it is ambiguous) and inside conditional clauses
(where users might use it incorrectly to test for equality) that we
disallow it. 

As the last example shows, we do leave people to fry in their own fat
if they use "<-" for comparisons with negative numbers, though (been
there, done that...)


-- 
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907

		
---------------------------------

	[[alternative HTML version deleted]]


