Alex Rivera | Logout

How to remove nested parentheses in LISP

Asked 2010-04-21T06:54:08.267
19

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

Edit
Report

1 Answer

26

Here's what I'd do:

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

That works mainly because I have Quicklisp installed already.

answered 2010-11-01T01:28:28.130

Your Answer