RosettaCodeData/Task/Flatten-a-list/Scheme/flatten-a-list.ss

9 lines
245 B
Scheme
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
> (define (flatten x)
(cond ((null? x) '())
((not (pair? x)) (list x))
(else (append (flatten (car x))
(flatten (cdr x))))))
> (flatten '((1) 2 ((3 4) 5) ((())) (((6))) 7 8 ()))
(1 2 3 4 5 6 7 8)