# Exercise 2.22 of SICP

Exercise 2.22: Louis Reasoner tries to rewrite the first square-list procedure of exercise 2.21 so that it evolves an iterative process:

(define (square-list items)
(if (null? things)
(iter (cdr things)
(cons (square (car things))
(iter items nil))


Unfortunately, defining square-list this way produces the answer list in the reverse order of the one desired. Why?

The reason the above works in reverse is because cons step of iter, cons puts new elements to the left of list answer.

(list 1 2 3) end up as (list 1), (list 2 1) and finally (list 3 2 1).

Louis then tries to fix his bug by interchanging the arguments to cons:

(define (square-list items)
(if (null? things)
(iter (cdr things)

Because (square (car things)) is not a list, cons creates a dotted pair out of answer which is an empty list and a number.
> (square-list (list 1 2 3 4))