A Function that Makes Closures
> (defun make-toggle (on-value off-value)
(let ((bit 0))
#'(lambda ()
(setq bit (- 1 bit))
(if (= bit 1) on-value off-value)
) ) )
MAKE-TOGGLE
> (setq traffic-light
(make-toggle 'green 'red) )
#<Interpreted Closure (unnamed) @ #x204c8fcb>
> (funcall traffic-light)
RED
> (funcall traffic-light)
GREEN
Previous slide
Next slide
Back to first slide
View graphic version