flat - LISP

(define (flat list) // flattens a list of lists into a single list
           (cond 
             ((null? list) ()) 
             ((list? (car list)) 
               (combine (flat (car list)) (flat (cdr list)))) 
             (T (cons (car list) (flat (cdr list)))) 
           ) 
) 

(define (combine X Y) // combine two lists
     (cond
         ((= () Y) X)
         (T (combine (append X (car Y)) (cdr Y)))
     )
 )


Last updated 2000/10/31
© J.A.N. Lee, 2000.