Wacek Kusnierczyk wrote: > > this is where multiple assignment might be your friend: > > source('http://miscell.googlecode.com/svn/rvalues/rvalues.r') > c(foo, bar, gee) := local({ > shared = 0 > foo = function() shared <<- 0 > bar = function(bar) shared <<- bar > gee = function() print(shared) > c(foo, bar, gee) }) >
... and of course, the functions do not need to be named within local, unless recursion, for example, is used: source('http://miscell.googlecode.com/svn/rvalues/rvalues.r') c(reset, set, get) := local({ shared = 0 c( function() shared <<- 0, function(bar) shared <<- bar, function() print(shared) ) }) the ugly <<- is used here, but always with reference to a variable found in the enclosing local scope, so the risk of messing with other variables in outer scopes is minimal. vQ ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.