Skip to content

Instantly share code, notes, and snippets.

@hyotang666
hyotang666 / flatten.lisp
Created March 18, 2015 05:51
When tree is deep nested, on lisp's flatten gets stack over flow.
(defun flatten(tree)
(let((result nil)
(head(car tree))
(tail(cdr tree)))
(tagbody top
(if(and(null tail)(null head))
(return-from flatten (nreverse result))
(if(consp head)
(progn
(push(cdr head)tail)
(defun find-all(item seq &rest args &key(test #'eql)test-not &allow-other-keys)
(apply #'remove item seq :test(when test-not test-not)
:test-not(unless test-not test)args))