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))
This popular question only has recursive solutions (not counting Rainer's answer).
Let's have a loop version:
(defun flatten (tree &aux todo flat)
(check-type tree list)
(loop
(shiftf todo tree nil)
(unless todo (return flat))
(dolist (elt todo)
(if (listp elt)
(dolist (e elt)
(push e tree))
(push elt flat))))))