Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;Define a Scheme function foo which finds all atoms inside an sexpression which pass a given predicate.
- ;;Examples:
- ;;(foo number? '(a (2 (c 3) 4)))
- ;;=> (2 3 4)
- ;;(foo symbol? '(a (2 (c 3) 4)))
- ;;=> (a c)
- ;;(foo symbol? 'a)
- ;;=> (a)
- ;;(foo number? 'a)
- ;;=> ()
- (define (foo p? s)
- (set! s (flatten s))
- (cond
- ((null? s) null)
- ((p? (car s)) (cons (car s) (foo p? (cdr s))))
- (else (foo p? (cdr s)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement