Hello Guys,

Following up my earlier mail where I am trying to write an alternative
front-end for R,  I had a question about accessing the closures and
environments in R code.

Here's the function taken  and modified a little from "*Lexical Scope and
Statistical Computing*"

=====================================================================
f<-function(){
  Rmlfun<-function(x){
    sumx  <-  sum(x)
    n <-  length(x)
    function(mu)
      n*log(mu)-mu*sumx
  }
  efun  <-Rmlfun(1:10)
  y1  <-  efun(3)
  print(y1)
  efun2  <-  Rmlfun(20:30)
  y2  <-  efun2(3)
  print(y2)
}
=====================================================================

Now assignment efun  <-Rmlfun(1:10) creates a closure where
*function(mu) n*log(mu)-mu*sumx *is returned and *sumx* and *n *are added
to the existing environment.

I can parse the code using *PROTECT(e =
R_ParseVector(tmp,1,&status,R_NilValue));* where tmp is the buffer
containing the same source. I can walk the resultant parser output and
build and alternative Abstract syntax tree(AST).

I would like to include the information about closure/environments in my
AST so that I can possibly do some optimizations.

My question is, how can I get hold of this information?

One thing I noticed while 'walking' through the parser output, I never
encounter a CLOSXP (which I check using TYPEOF()) , even though in the
above code, closure is created. Is it the case that this information is
meant just for the internal "eval*" function and not exposed application
writers?

Thanks,
Rob

	[[alternative HTML version deleted]]

