Side-effects vs. functional programming

RScheme, like Scheme itself, is a language with side-effects. However, a "mostly functional" style is encouraged.

Consider the two short lists, constructed as follows:

(set! a (list (make-bar 1) (make-foo 2)))
(set! b (list (make-baz 3) (make-baz 4)))

The resulting structure is as follows:

Figure 5-1. List structure after side-effects.

Call the return value of (append a b) c, and you have the following circumstance. Note that the c and b lists share structure

Figure 5-2. List after append

On the other hand, if d is the result of calling (append! a b), then the following figure applies. Note that the a and d lists share structure in this case, in addition to the same kind of shared structure with the b list.

Figure 5-3. List after append!