RE: (dsssl) flatten list procedure

Subject: RE: (dsssl) flatten list procedure
From: "Maltby, David G" <david.g.maltby@xxxxxxxx>
Date: Wed, 18 Apr 2001 11:07:00 -0400
Hello Eric -

From: Eric Brunel [mailto:eric_brunel@xxxxxxxx]
> Hi David,
> > I would like to have a procedure that takes a list,
> > which may be a list of
> > lists, and returns a flattened list.  For example
> > with input list ((a b) c d
> > ((e f g) h i)) it would return (a b c d e f g h i),
> 
> A long-time Lisp programmer like me would do something
> like that:
> 
> (define (flatten l)
>   (cond ((null? l) '())
>         ((list? l)
>          (append (flatten (car l)) (flatten (cdr l))))
>         (else (list l))
>   )
> )
> [snip]
> list (so "(flatten 'a)" will be "(a)" - don't know if
> this is what you want...)

Yes, this is what I want.

> It should work (but I haven't tested it...).

It works beautifully.
 
> But maybe it isn't in the DSSSL way of thinking...

This is almost assuredly a DSSSL way of thinking, unfortunately I don't
always think in a DSSSL way. (append) was what I was not thinking about.
Thank you, Eric.

Best Regards, David

 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist

Current Thread