Full_Name: Elliott Forney Version: 2.9.2 OS: Linux, Fedora 10 Submission from: (NULL) (129.82.47.235)
The following code creates a list of functions that are lexically closed over a single argument. If a print statement is included then each function in the list evaluates to a different value. If the print statement is not included then each function evaluates to something different, as expected. I am convinced that this behavior is not correct as one would not expect the presence of a lone print statement to alter the behavior of a program. Please let me know if you have any questions and thank you for your time. The sample code follows: ## returns a function that sums input with 5 funk <- function(input) { ## expected behavior if either of ## the following lines is uncommented # print(input) # input <- input ## function to sum input with 5 ## lexical closure over input function() { input + 5 } } ## create a list different funk's funk.list <- list() for (i in 1:5) { ## just some values to sum over test.vector <- 1:i ## add funk that sums test.vector with 5 funk.list[[i]] <- funk(sum(test.vector)) } ## print result of evaluating each funk ## They are all the same unless print or ## reflexive assignment is uncommented!! for (i in 1:5) print(funk.list[[i]]()) ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel