Completed 2.23
This commit is contained in:
parent
a6b0a5b3b5
commit
751556bc37
|
@ -0,0 +1,10 @@
|
||||||
|
(define (square x) (* x x))
|
||||||
|
|
||||||
|
(define (square-list-1 items)
|
||||||
|
(if (null? items)
|
||||||
|
'()
|
||||||
|
(cons (square (car items)) (square-list-1 (cdr items)))))
|
||||||
|
|
||||||
|
(define (square-list-2 items)
|
||||||
|
(map square items))
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
The list is in the reverse order because each call to cons puts the next
|
||||||
|
item in front of the previous one. We are iterating through the input
|
||||||
|
list from left to right but are adding to the result from right to left.
|
||||||
|
|
||||||
|
The second solution doesn't work because cons takes a single value as
|
||||||
|
its first value and a list as its second.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue