[gambit-list] Android Gambit Error

vasil vasil.s.d at gmail.com
Thu Sep 15 00:46:41 EDT 2011


Take a look at: http://en.wikipedia.org/wiki/Closure_%28computer_science%29

> On a final note, I am mystified as to how the code works.  This is an
> example of it being defined and run on my Windows 7x64 machine:
> 
> Gambit v4.6.1
> 
>> (define (counter)
>         (let ((value 0))
>               (lambda ()
>                   (set! value (+ value 1))
>                   value)))
>> (define first-counter (counter))
>> (first-counter)
> 1
>> (first-counter)
> 2
>> (first-counter)
> 3
>> (first-counter)
> 4
>>
> 
>  It seems to initialize value to 0 and I assume that happens the first
> time you use (counter) to define another form.  What I don't understand
> is why the code for initializing is skipped every time (first-counter)
> is run.
> 
> TIA, Steve
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list