From: Darren Teemull

Subject: My clumsy solution to flattening

Date: 1999-3-3 7:39

Thanks for all the suggestions from the people who responded to my
earlier questions. This is what I finally came up with (Sorry, but I
don't think it matches anyone's suggestion, but that's simply because of
my ineptness at Lisp) feel free to rip it apart and improve on it if you
like.

Solution to the flattening and combining of two lists, each containing
any amount of nested lists and brackets (eg. 1=((a b) c) & 2=(d ((e) f))
then (flatten 1 2) = (a b c d e f)) :

(defun flatten (fl1 fl2)
    (cond ((null fl2) NIL)
              (t (cond ((null fl1) (flatten fl2 (cdr fl2)))
                           ((listp (car fl1))
                               (cons (car (flatten (car fl1) fl2))
                               (if (null (cdr (car fl1)))
                                   (flatten (cdr fl1) fl2)
                                   (flatten (cons (cdr (car fl1)) (cdr
fl1)) fl2))))
                           (t (cons (car fl1) (flatten (cdr fl1)
fl2)))))))

Thanks & Later,
DFT
Software Engineering student, University of Toronto