How does one transform that pseudo code in R, such that all binding are freezed at the state they were when the function were defined ?
lastfunction <- function(inputx) {rep(0,length(inputx))}
i<-1
while(i<=2){
afunction <- function(inputx) {i*inputx} #freeze all variable used in the body
lastfunction <- lastfunction + afunction #and of course the label "afunction" as well
i<-i+1
}
#then apply to some data
lastfunction(c(0,1,5,6))
I looked at environments but can't see how to to it properly (nesting environments ?)