On 29/01/2010 2:03 PM, Saptarshi Guha wrote:> Dear R Users,
> Using codetools I obtained the text representation of the parse tree for
this
> snippet
>
>
> z=quote({x[1]<-2})
> showTree(z)
>
> > ("{" (<- ([ x 1) 2)) (A)
>
> If I understand correctly, x[1]<-2 ought to be
"[<-"(x,1,2), so shouldn't i see
>
> ("{" ( [<- x 1 2 ) )
>
> If indeed the parse tree in (A) is correct, the operation ([ x 1)
> returns the value of x[1], how then does
> the <- operator know to change the 1st element of x ? Does the <-
> implementation inspect the its 1st argument (e.g if it sees
> [ call, it instead changes itself to implementation of "[<-"?
The displayed parse tree is correct. You could confirm it by looking at
z[[1]], z[[2]], z[[2]][[1]], etc.
The [ call is the first argument to <-, which is the destination of the
assignment. The conversion to [<- happens at evaluation time.
Duncan Murdoch