読者です 読者をやめる 読者になる 読者になる

(wat-aro)

無職から有職者にランクアップしました

SICP 問題 4.05

make-ifに渡す前にclauseをpredicateとactionにわかる. (car action)に'=>があれば(cadr action)にpredicateを適用する.

(define (expand-clauses clauses)
  (if (null? clauses)
      'false ;; else 説は無い
      (let ((first (car clauses))
            (rest (cdr clauses)))
        (if (cond-else-clause? first)
            (if (null? rest)
                (sequence->exp (cond-actions first))
                (error "ELSE clause isn't last: COND->IF"
                       clauses))
            (let ((predicate (cond-predicate first))
                  (action (cond-action first)))
              (make-if (cond-predicate first)
                       (if (eq? (car action) '=>)
                           ((cadr action) predicate)
                           (sequence->exp action))
                       (expand-clauses rest)))))))