Closure Example 1
The adder fn:
> (defun add-to-list (num lst)
(mapcar #'(lambda (x) (+ x num)) lst))
ADD-TO-LIST
> (defun make-adder (n)
#'(lambda (x) (+ x n)))
MAKE-ADDER
> (setf add5 (make-adder 5))
#<closure 1 #xDDF914>
> (setf add15 (make-adder 15))
#<closure 1 #xDE2F34>
> (funcall add5 1)
6
> (funcall add15 1)
16
Previous slide
Next slide
Back to first slide
View graphic version