A set!-expression, also known as an ASSIGNMENT, has the following shape:
(set! var exp)It consists of a variable, the LEFT-HAND SIDE, and an expression, called RIGHT-HAND SIDE. The left-hand side of a set!-expression is a fixed variable. In this book, we only use variables that are defined, either at the top-level or in a local-expression. A set!-expression may occur wherever an expression is legal.
The value of a set!-expression is always the same and is moreover invisible. It is therefore irrelevant. What matters about a set!-expression, instead, is the effect of its evaluation. Specifically, for the first step of the evaluation of a set!-expression, we determine the value of exp. Let's say this value is V. For the second step, we change the definition of var to
(define var V)The EFFECT of this second step is that from this point on, all references to var in an evaluation replace var by V.
Understanding the true nature of assignments is difficult. We therefore first consider a simple though useless example.