0

Since i have just made my foray into R, I came across the following set of function calls:

myFunc<-function(x=matrix())
 {
  temp<-NULL
  set<-function(y)
  {
   x<<-y
   temp<<-NULL
  }
  get(){ x }
  setT(t){ temp<<-T }
  getT(){ Temp }
  list(set=set,get=get,setT=setT,getT=getT)
 }

In the Second function with the following header:

anotherFunc<-function(x)

There is a statement that reads,

randomvariable<-x$getT()

Now what i'm trying to understand is how is this statement different from any other function call. What are the implications of referencing x to call the function getT(). Is there any similarity between the call by reference used in Java, C++?

PS- In case there is mistake in the question format, please do mention since i'm new to SO.

Roland
  • 127,288
  • 10
  • 191
  • 288
  • Please make your code reproducible. – Roland Mar 21 '15 at 08:46
  • By mentioning reproducible, do you want me to add the second function? – Akshay Kumar Mar 21 '15 at 11:08
  • This question is too broad, SO is for exact practical problems. Are there similarities? Yeah, there are functions and you call them. Assuming what you're alluding to here is the fact this list kind of looks like a ghetto object well it kind of does, but what you're doing in R looks more like a HashMap with functors in java than an object – Lev Kuznetsov Mar 21 '15 at 12:04
  • I agree--this looks like a kludgy attempt at a closure, but hard to tell without seeing all of the defined functions (setT and getT are missing). You may find this comparison of R's different OO-like systems helpful: http://stackoverflow.com/a/9522858/636656 – Ari B. Friedman Mar 21 '15 at 12:48
  • Thank you all for the replies, i kind of got to know my mistake, and i agree i wasn't able to present it in a crisp and precise manner. Will take care of it in the future. – Akshay Kumar Mar 21 '15 at 20:56

0 Answers0