government / testdata / scoping.gov.lisp

@ bdd32d2bb7ca2a1b5b8c192fbaab691d8f1ed255 | history


; Scope is lexical: a function sees the bindings where it was written,
; not where it is called.
(define x 1)
(define f (lambda () x))
(define g (lambda (x) (f)))
(g 2)                 ;=> 1
(define x 2)          ;=! immutable
((lambda (x) (define y (+ x 1)) (define z (+ y 1)) z) 1)   ;=> 3
((lambda () (define a (lambda () (b))) (define b (lambda () 1)) (a)))   ;=! unbound