Created
April 11, 2013 03:00
-
-
Save yao2030/5360311 to your computer and use it in GitHub Desktop.
Derived expressions for and & or, SICP Ex4.4
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 (and->if exp) | |
(expand-and-clauses (and-clauses exp))) | |
(define (expand-and-clauses clauses) | |
(if (null? clauses) | |
true | |
(let ((first (car clauses)) | |
(rest (cdr clauses))) | |
(if (false? first) | |
'f | |
(make-if first (expand-and-clauses rest) false))))) | |
(define (or->if exp) | |
(expand-if-clauses (or-clauses exp))) | |
(define (expand-or-clauses clauses) | |
(if (null? clauses) | |
false | |
(let ((first (car clauses)) | |
(rest (cdr clauses))) | |
(if first | |
(make-if first true (expand-or-clauses rest)) | |
true)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment