(define (fringe tree) ; right-fringe contains the fringe of the tree excluding node which is all ; the leaves in node's right sibling and node's ancestors' right siblings. ; iter returns the fringe excluding leafs from node's left siblings and nodes ; ancestors' left siblings. (define (iter node right-fringe) (cond ((null? node) right-fringe) ((not (pair? node)) ; leaf (cons node right-fringe)) (else (iter (car node) (iter (cdr node) right-fringe))))) (iter tree '())) ; 1 ]=> (define x (list (list 1 2) (list 3 4))) ; ; ;Value: x ; ; 1 ]=> (fringe x) ; ; ;Value: (1 2 3 4) ; ; 1 ]=> (define y (list 1 2 (list 3 (list 4 5) 6) 7 8 (list (list 9)))) ; ; ;Value: y ; ; 1 ]=> y ; ; ;Value: (1 2 (3 (4 5) 6) 7 8 ((9))) ; ; 1 ]=> (fringe y) ; ; ;Value: (1 2 3 4 5 6 7 8 9)