(define-structure (parent bindings)) (define-function scope-new (parent) (new parent)) (define-function scope-find (self key) (assq key (-bindings self))) (define-function scope-lookup (self key) (and self (or (scope-find self key) (scope-lookup (-parent self) key)))) (define-function scope-define (self key value) (let ((binding (scope-find self key))) (if binding (set-cdr binding value) (set binding (cons key value)) (push (-bindings self) binding)) binding)) (define-function scope-define-global (self key value) (while (-parent self) (set self (-parent self))) (scope-define self key value))