How to remove nested parentheses in LISP
Posted: Tue Apr 20, 2010 7:52 pm
I need to write a recursive function which will "collapse" a list, that is, remove all nested parentheses so that the atoms are all at the top level.
(collapse '(a b c (d e) ((f) g))) => (a b c d e f g)
(collapse '(a b)) => (a b)
(collapse '(() ((((a)))) ())) => (a)
Thanks
(collapse '(a b c (d e) ((f) g))) => (a b c d e f g)
(collapse '(a b)) => (a b)
(collapse '(() ((((a)))) ())) => (a)
Thanks