(define (flatten tree) (cond ((null? tree) nil) ((not (pair? tree)) (list tree)) (else (append (flatten (car tree)) (flatten (cdr tree))))))
Not I would like to do something like
(define (flatten tree) (map <??> tree))
Where both of these will produce '(1 2 3 4 5) when passed in '(1 (2 (3 4) 5))
I am unsure of what kind of function to pass into map, to me it seems like the process decomposes fairly naturally into two cases. Either the car input is a pair or an element, if it is an element, it should pass it onto map, if it is a pair I am not sure where to proceed.
It seems that if it is an element you want to recurse into tree further, but recursing onto car, and cdr produces a function akin to the first posted.
Any help would be appreciated, I've been trying to find the answer for quite a while without luck.