Skip to content
Prev 359468 / 398502 Next

Persistent state in a function?

Martin, All:

A very nice point! Perhaps the following may help to illustrate it.

g <- function(){
  x <- NULL
  function(y){cat("result is ",x," \n"); x <<- y}
}
result is
result is  1
result is  3


Best,
Bert





Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Mar 21, 2016 at 2:41 AM, Martin Maechler
<maechler at stat.math.ethz.ch> wrote: