X-Git-Url: http://git.kpe.io/?p=kmrcl.git;a=blobdiff_plain;f=lists.lisp;h=ecdd003f993ec85dd20ee160f23017cb0c2eefb3;hp=5cd193cefe96910174ef1c9a9a5039c0b1c9b7b5;hb=251043d4c96c996a35cd48c4452b03fbef2ea21a;hpb=5a1ba26220b15f493fac354c0e411c1f2f57d20d diff --git a/lists.lisp b/lists.lisp index 5cd193c..ecdd003 100644 --- a/lists.lisp +++ b/lists.lisp @@ -7,8 +7,6 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2000 ;;;; -;;;; $Id$ -;;;; ;;;; This file, part of KMRCL, is Copyright (c) 2002 by Kevin M. Rosenberg ;;;; ;;;; KMRCL users are granted the rights to distribute and use this software @@ -73,11 +71,14 @@ 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 (consp item) + (map nil #'scan item) + (push item result)))) + (scan tree)) + (nreverse result))) ;;; Keyword functions