sicp-solutions/chapter-2/ex-2.22.txt

18 lines
581 B
Text

When we are running the iter line:
(iter (cdr things)
(cons (square (car things))
answer))))
We are essentially pushing on the "answer" accumulator list
like a stack, so when we start with items = (1 2 3), answer =
().
When we run the loop once we get:
things = (2 3), answer = (1)
things = (3), answer = (4 1)
things = (), answer = (9 4 1).
When Louis changes the order in the cons, he just produces the
following:
things = (1 2 3), answer = ()
things = (2 3), answer = (() . 1)
things = (3), answer = ((() . 1) . 4)
things = (), answer = (((() . 1) . 4) . 9)