-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2.22.scm
28 lines (26 loc) · 841 Bytes
/
2.22.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
;; (define (square-list items)
;; (define (iter things answer)
;; (if (null? things)
;; answer
;; (iter (cdr things)
;; (cons (square (car things)) -> new item is located first
;; answer))))
;; (iter items nil))
;; (define (square-list items)
;; (define (square x) (* x x))
;; (define (iter things answer)
;; (if (null? things)
;; answer
;; (iter (cdr things)
;; (cons answer -> (cons list atom) is not plain list
;; (square (car things))))))
;; (iter items nil))
(define (square-list items)
(define (square x) (* x x))
(define (iter things answer)
(if (null? things)
answer
(iter (cdr things)
(append answer
(list (square (car things)))))))
(iter items nil))