Hi, Leo.  Yes, that's exactly the idea.  Thanks,

-- Mike




>
>From: Leo Guelman <leo.guelman@gmail.com>
>To: Michael Hannon <jm_hannon@yahoo.com>
>Cc: R Help <r-help@r-project.org>
>Sent: Mon, July 25, 2011 3:16:13 PM
>Subject: Re: [R] Simple example of using a closure in R to manage bank 
accounts?
>
>
>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_hannon@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]]

