Next: , Previous: , Up: scheme overview   [Index]


3.1.10 Assignment

Scheme variables bound by definitions or let or lambda expressions are not actually bound directly to the objects specified in the respective bindings, but to locations containing these objects. The contents of these locations can subsequently be modified destructively via assignment:

(let ((x 23))
  (set! x 42)
  x) ⇒ 42

In this case, the body of the let expression consists of two expressions which are evaluated sequentially, with the value of the final expression becoming the value of the entire let expression. The expression (set! x 42) is an assignment, saying “replace the object in the location referenced by ‘x’ with ‘42’”. Thus, the previous value of ‘x’, ‘23’, is replaced by ‘42’.