sicp-solutions/ex-2.22.txt
Petar Kapriš da96368e0b Add solutions to exercises from subsection 2.2.1
In exercise 2.17, there is an error with the test on hexlets site, which
should be reported to them.
2025-02-06 11:08:54 +01:00

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)