sample problem: streams (2)
- problem
take the tree from before
define a procedure that converts a tree to a stream
containing key/value pairs in depth first order.
use this to implement depth-frst search
- code
(define (streamify t k)(define (dfs trees) (if (null? trees)
the-empty-stream
(let ((t1 (car trees))) (cons-stream (cons (key t1) (val t1)) (dfs (append (next t1) (cdr trees))))))) (dfs (list t)))
(define (search t k)(filter-stream (lambda (e) (eq? (key e) k)) (streamify t)))