Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created December 11, 2012 07:36
Show Gist options
  • Save yao2030/4256610 to your computer and use it in GitHub Desktop.
Save yao2030/4256610 to your computer and use it in GitHub Desktop.
(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