이 문제는 리스트를 인자로 받아 모든 원소를 제곱하여 다시 리스트로 내놓는

square-list 프로시저를 만드는 문제입니다.

 

c19

이 문제는 빈칸 채우기라 그리 어렵지 않았습니다.

 

 

참조

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))

크리에이티브 커먼즈 라이선스
Creative Commons License
TAG , , ,

글에 잘못된 점, 다른 점, 부족한 점이 있다면 지적해주세요.
댓글, 트랙백, 메일 모두 고맙습니다.

트랙백 주소 :: http://nosyu.pe.kr/trackback/1319

댓글을 달아 주세요

[로그인][오픈아이디란?]