Last active
December 16, 2015 02:09
-
-
Save yao2030/5360463 to your computer and use it in GitHub Desktop.
SICP Exercose 4.5, without peeking at others's code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (expand-clauses clauses) | |
(if (null? clauses) | |
'false ; no else clause | |
(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" | |
clauese)) | |
(if (cond=>clause? first) | |
(let ((val (car first))) | |
(if val | |
(list (caddr first) val) | |
(make-if (cond-predicate first) | |
(sequence->exp (cond-actions first)) | |
(expand-clauses rest))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment