flatten

Ralf Juengling <[email protected]>
Newsgroups gmane.lisp.lush.devel
Message-ID <[email protected]>
? ^Aflatten

------------------------------------------------------------------------
(flatten <x>)                                 [DX]
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Returns all the atoms in x , linked in a single list.

Example:
? (flatten '2)
= (2)

? (flatten '(1 2 (3 (6 7)) 4))
= (1 2 3 6 7 4)



I wanted to use 'flatten' the other day, thinking that it would
yield a list of all leafes in a tree in the order of a
depth first left-to-right traversal. But it leaves out all nils,
although nils are atoms.


Here is what I think how it should work:

(de flatten2 (arg)
   (if (consp arg)
       (let (((a . b) arg))
 	(nconc (flatten2 a) (flatten2 b)) )
     (list arg) ))

? (flatten2 '(1 2 (3 (6 7)) 4))
= (1 2 3 6 7 () () 4 ())


I think either the behavior of flatten should be changed to
that of flatten2, or the help text should be clarified.

Regards,
Ralf



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.