something like this maybe?

account <- function (balance=0) {
         function (d = 0,w = 0) {
    newbal <- balance + d - w
       balance <<- newbal
       newbal
       }
            }
John <- account(100)
John
John(d=100,w=50)
John()

Leo <- account(1000)
Leo
Leo(d=1000,w=50)
Leo()
Leo(d=100,w=500)
Leo()
Leo.

On Mon, Jul 25, 2011 at 6:00 PM, Michael Hannon <jm_han...@yahoo.com> wrote:

> Greetings.  I once ran across a simple (toy) example of using a closure in
> R to
> manage bank accounts.  I've got a use for it now but can no longer find it.
>  If
> you have it (or a similar example), will you please send it to me?
> (Unfortunately, a web search that includes the terms "bank" and "closure"
> leads
> into a whole pile of unrelated stuff.)
>
> Thanks,
>
> -- Mike
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to