(wat-aro)

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

SICP 問題 4.26

unlessを特殊形式で定義する.

(define (analyze exp)
  (cond ((self-evaluating? exp) (analyze-self-evaluating exp))
        ((quoted? exp) (analyze-quoted exp))
        ((variable? exp) (analyze-variable exp))
        ((assignment? exp) (analyze-assignment exp))
        ((definition? exp) (analyze-definition exp))
        ((if? exp) (analyze-if exp))
        ((unless? exp) (analyze (unless->if exp)))
        ((lambda? exp) (analyze-lambda exp))
        ((let? exp) (analyze (let->combination exp)))
        ((begin? exp) (analyze-sequence (begin-actions exp)))
        ((cond? exp) (analyze (cond->if exp)))
        ((application? exp) (analyze-application exp))
        (else (error "Unknown expression type: ANALYZE" exp))))

(define (unless-condition exp) (cadr exp))
(define (unless-usual-value) (caddr exp))
(define (unless-exceptional-value) (cadddr exp))

(define (unless? exp) (tagged-list? exp 'unless))

(define (unless->if exp)
  (make-if (unless-condition exp)
           (unless-exceptional-value exp)
           (unless-usual-value exp)))

unlessが特殊形式だと困る理由はここで wat-aro.hatenablog.com