sicp-solutions/chapter-2/ex-2.28.scm

16 lines
482 B
Scheme

#lang sicp
(define (list? x)
(or (null? x) (pair? x)))
(define (fringe tree)
(if (null? tree)
'()
(let* ((head (car tree))
(tail (cdr tree))
(h-list (if (list? head) ; if it's a subtree
(fringe head) ; turn it into a list
; otherwise, just make a
; one-element list
(list head))))
(append h-list (fringe tail)))))