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 : http://fr.messenger.yahoo.com DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
(dsssl) flatten list procedure, Maltby, David G | Thread | RE: (dsssl) flatten list procedure, Maltby, David G |
(dsssl) flatten list procedure, Maltby, David G | Date | RE: (dsssl) flatten list procedure, Maltby, David G |
Month |