Tuesday, 15 February 2011

r - Create reference to an object -



r - Create reference to an object -

question r contains concept of reference object.

in python, equal operator is, in fact, re-create reference. example:

>> = [1,2,3] >> b = >> b[1] = 10 >> [1, 10, 3]

or in c++

vector a(3); a[1] = 1; vector& b = a; b[1] = 10; // a[1] = 10

you should @ reference classes, can utilize plain old environments:

> a=new.env() > a$data=c(1,2,3) > b=a > b$data [1] 1 2 3 > a$data[1]=99 > b$data [1] 99 2 3

a , b same environment:

> <environment: 0xa1799fc> > b <environment: 0xa1799fc>

so contents same objects.

i think of other r oo systems (r.oo, proto?) utilize environments implement oo objects , methods.

so, although can this, action-at-a-distance effects can cause hard find bugs, , shouldn't.

r

No comments:

Post a Comment