How to remove nested parentheses in LISP

bubdada picture bubdada · Apr 21, 2010 · Viewed 16.7k times · Source

How can I remove nested parentheses recursively in Common LISP Such as

  (unnest '(a b c (d e) ((f) g))) => (a b c d e f g)
  (unnest '(a b))                 => (a b)
  (unnest '(() ((((a)))) ()))     => (a)

Thanks

Answer

Xach picture Xach · Nov 1, 2010

Here's what I'd do:

(ql:quickload "alexandria")
(alexandria:flatten list)

That works mainly because I have Quicklisp installed already.