A Procedure that Makes Closures
> (define (make-toggle on-value off-value)
(let ((bit 0))
(lambda ()
(set! bit (- 1 bit))
(if (= bit 1) on-value off-value)
) ) )
> (define traffic-light
(make-toggle 'green 'red) )
> (traffic-light)
red
> (traffic-light)
green
Previous slide
Next slide
Back to first slide
View graphic version