Created
December 11, 2012 07:36
-
-
Save yao2030/4256610 to your computer and use it in GitHub Desktop.
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 (filter predicate sequence) | |
(cond ((null? sequence) '()) | |
((predicate (car sequence)) | |
(cons (car sequence) | |
(filter predicate (cdr sequence)))) | |
(else (filter predicate (cdr sequence))))) | |
(define (accumulate op initial sequence) | |
(if (null? sequence) | |
initial | |
(op (car sequence) | |
(accumulate op initial (cdr sequence))))) | |
(define (enumerate-interval low high) | |
(if (> low high) | |
'() | |
(cons low (enumerate-interval (+ low 1) high)))) | |
(define (enumerate-tree tree) | |
(cond ((null? tree) '()) | |
((not (pair? tree)) (list tree)) | |
(else (append (enumerate-tree (car tree)) | |
(enumerate-tree (cdr tree)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment