Created
March 18, 2015 05:51
-
-
Save hyotang666/2d6487a05bb39615ed4d to your computer and use it in GitHub Desktop.
When tree is deep nested, on lisp's flatten gets stack over flow.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) | |
(setf head(car head)) | |
(go top)) | |
(progn | |
(unless(null head) | |
(push head result)) | |
(setf head(pop tail)) | |
(go top))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment