Skip to content
Prev 14241 / 398506 Next

recursive functions and global variables

On Sun, Oct 14, 2001 at 08:00:49PM -0500, David A Richmond wrote:
new.env and environment are functions--assigning to them as variables
doesn't do anything useful. But do you really need explicit
environment manipulation or is ordinary lexical scoping of definitions
enough?  That is,

test <- function(x) {
    test2 <- function() {
 	cat("x =",x,"\n")
 	cat("b =",b,"\n")
 	return(b+1.1)
    }
    b <- x^2
    test2()
}

test(3)

If you want to use explicitly constructed environments then you need
to access their contents by explicit calls to get or by explicit evals
in the environment.

Your original motivation for this was to prevent copying, but
arguments to functions are not copied, just marked as needing to be
copied on modify. So you may not really need any of this.

  
    
Message-ID: <20011015051818.A16715@nokomis.stat.umn.edu>
In-Reply-To: <Pine.GSO.4.20.0110141954020.12070-100000@jade.saintmarys.edu>; from richmond@saintmarys.edu on Sun, Oct 14, 2001 at 08:00:49PM -0500