encapsulation
compare these
- procedure that modifies global var
(define down1 (lambda (i) (set! x (- x i)) x))
- procedure that modifies local var
(define down2 (let ((x 100)) (lambda (i) (set! x (- x i)) x)))
- what does this interaction produce when down is down1 down2?
(define x 100)
(down 5) 95 95
x 95 100
(down 5) 90 90
(set! x 100)
(down 5) 95 85
note
- down2’s x cannot be accessed (read or write!) at the top level, except by executing down2
- that x is said to be encapsulated