Skip to content
Prev 175747 / 398503 Next

Definition of = vs. <-

On 4/1/2009 10:38 AM, Stavros Macrakis wrote:
The parser does treat them differently:

 > if (x <- 2) cat("assigned\n")
assigned
 > if (x = 2) cat("assigned\n")
Error: unexpected '=' in "if (x ="

The ?"=" man page explains this:

" The  operator '<-' can be used anywhere,
      whereas the operator '=' is only allowed at the top level (e.g.,
      in the complete expression typed at the command prompt) or as one
      of the subexpressions in a braced list of expressions. "

though the restriction on '=' seems to be described incorrectly:

 > if ((x = 2)) cat("assigned\n")
assigned

in which the assignment is in parentheses, not a braced list.

As to the difference between the operations of the two primitives:  see 
do_set in src/main/eval.c.  The facility is there to distinguish between 
them, but it is not used.

Duncan Murdoch