projects
/
kmrcl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
91bc227
)
optimize flatten function
author
Kevin M. Rosenberg
<kevin@rosenberg.net>
Mon, 22 Mar 2010 19:35:00 +0000
(13:35 -0600)
committer
Kevin M. Rosenberg
<kevin@rosenberg.net>
Mon, 22 Mar 2010 19:35:00 +0000
(13:35 -0600)
lists.lisp
patch
|
blob
|
history
diff --git
a/lists.lisp
b/lists.lisp
index 5cd193cefe96910174ef1c9a9a5039c0b1c9b7b5..eaa3f9d372aa601d079d6f24ead4798bc17ea467 100644
(file)
--- a/
lists.lisp
+++ b/
lists.lisp
@@
-73,11
+73,14
@@
it
nil)))))
it
nil)))))
-(defun flatten (lis)
- (cond ((atom lis) lis)
- ((listp (car lis))
- (append (flatten (car lis)) (flatten (cdr lis))))
- (t (append (list (car lis)) (flatten (cdr lis))))))
+(defun flatten (tree)
+ (let ((result '()))
+ (labels ((scan (item)
+ (if (listp item)
+ (map nil #'scan item)
+ (push item result))))
+ (scan tree))
+ (nreverse result)))
;;; Keyword functions
;;; Keyword functions