; an early lisp program
(define (atom? x)
(and (not (pair? x)) (not (null? x))))
(define (collapse l)
(cond ((atom? l) (cons l '()))
((null? (cdr l))
(cond ((atom? (car l)) l)
(else (collapse (car l)))))
(else (append (collapse (car l))
(collapse (cdr l))))))
(display (collapse '((((a b) ((c))) ((d (e f)) (g) ((h))))))) (newline)
(display (collapse '((a (b (c (d (e))) f (g (h j))))))) (newline)
(display (collapse '((((((a) b) c) d) e)))) (newline)