이 문제는 프로시저와 리스트를 인자로 받아 리스트 원소에 프로시저를 적용시켜
그 값을 리스트가 아닌 형태로 결과를 내놓는 for-each 프로시저를 만드는 문제입니다.

리턴되는 값은 무엇이든 상관없다고 하였으니 참(true)로 잡았습니다.
그리고 되도는 프로세스와 반복 프로세스로 만들었습니다.
(앞의 문제에서 반복이 되지 않아서...;;;;)
참조
Structure and Interpretation of Computer Programs 2/E - Page 139
; answer
(define (my-for-each proc items)
(define (iter n_list)
(cond ((null? n_list) (= 0 0)) ; return true
(else (proc (car n_list))
(iter (cdr n_list)))))
(iter items))
(define (my-for-each2 proc items)
(cond ((null? items) (= 0 0))
(else (proc (car items))
(my-for-each2 proc (cdr items)))))
; execute
(for-each (lambda (x) (newline) (display x))
(list 57 321 88))
(newline)
(my-for-each (lambda (x) (newline) (display x))
(list 57 321 88))
(newline)
(my-for-each2 (lambda (x) (newline) (display x))
(list 57 321 88))
- SICP Exercise 연습문제 2.26 (0)2008/02/04
- SICP Exercise 연습문제 2.25 (0)2008/02/04
- 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
글에 잘못된 점, 다른 점, 부족한 점이 있다면 지적해주세요.
댓글, 트랙백, 메일 모두 고맙습니다.







댓글을 달아 주세요