이 문제는 리스트를 인자로 받아 모든 원소를 제곱하여 다시 리스트로 내놓는
square-list 프로시저를 만드는 문제입니다.

이 문제는 빈칸 채우기라 그리 어렵지 않았습니다.
참조
Structure and Interpretation of Computer Programs 2/E - Page 138
(define (square x) (* x x))
; map
(define (map proc items)
(if (null? items)
null
(cons (proc (car items))
(map proc (cdr items)))))
; square-list
(define (square-list1 items)
(if (null? items)
null
(cons (square (car items)) (square-list1 (cdr items)))))
(define (square-list2 items)
(map square items))
; execute
(square-list1 (list 1 2 3 4))
(square-list2 (list 1 2 3 4))
"in OCW" 카테고리의 다른 글
- SICP Exercise 연습문제 2.24 (0)2008/02/04
- SICP Exercise 연습문제 2.23 (0)2008/02/04
- SICP Exercise 연습문제 2.22 (0)2008/02/04
- SICP Exercise 연습문제 2.21 (0)2008/02/04
- SICP Exercise 연습문제 2.20 (0)2008/02/02
- SICP Exercise 연습문제 2.19 (0)2008/02/02
- SICP Exercise 연습문제 2.18 (0)2008/02/02
글에 잘못된 점, 다른 점, 부족한 점이 있다면 지적해주세요.
댓글, 트랙백, 메일 모두 고맙습니다.







댓글을 달아 주세요