Closures that Share Bindings
> (define (make-stack)
(let ((stack () ))
(cons
(lambda (item) ; closure for push.
(set! stack (cons item stack)) )
(lambda () ; closure for pop.
(if (pair? stack)
(begin
(let ((top (car stack)))
(set! stack (cdr stack))
top) )
() ) )
) ) )
Previous slide
Next slide
Back to first slide
View graphic version