Bindings are Stacked

When the value of a symbol is changed (e.g. by set!), the existing binding is changed to point to the new value. However, when Lisp binds a variable upon entry to a function, pre-existing values of that variable (if any) are not replaced. Instead, the new value is bound in a new stack frame. When the function exits, this stack frame is popped off, leaving the previous values of symbols intact.


   (define n 5)

(factorial 3)

n

Although factorial uses the variable n, the evaluation of n after calling factorial returns 5, its previous binding.

Rule: There are always fresh bindings of function arguments and let variables each time a function is entered. These bindings vanish when the function exits.

Contents    Page-10    Prev    Next    Page+10    Index