Re: (dsssl) flatten list procedure

Subject: Re: (dsssl) flatten list procedure
From: Eric Brunel <eric_brunel@xxxxxxxx>
Date: Wed, 18 Apr 2001 16:05:02 +0200 (CEST)
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))
which means in short:
- if the list is empty, just return the empty list
- if the list is a real list, flatten its car, flatten
its cdr and append the resulting lists
- if the list is not a list, return the "atom" in a
list (so "(flatten 'a)" will be "(a)" - don't know if
this is what you want...)

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

But maybe it isn't in the DSSSL way of thinking...
 - eric -

Do You Yahoo!? -- Pour dialoguer en direct avec vos amis, 
Yahoo! Messenger :

 DSSSList info and archive:

Current Thread