Added (flatten)

This commit is contained in:
Justin Ethier 2016-08-06 18:54:18 -04:00
parent 5f88a68525
commit e044c362c2

View file

@ -40,6 +40,7 @@
gensym gensym
delete delete
delete-duplicates delete-duplicates
flatten
list-index2 list-index2
list-insert-at! list-insert-at!
list-prefix? list-prefix?
@ -103,6 +104,11 @@
(if (eq? tail new-tail) lis (cons x new-tail))))) (if (eq? tail new-tail) lis (cons x new-tail)))))
(recur lis)) (recur lis))
(define (flatten x)
(cond ((null? x) '())
((pair? x) (append (flatten (car x)) (flatten (cdr x))))
(else (list x))))
;; Insert obj at index k of list, increasing length of list by one. ;; Insert obj at index k of list, increasing length of list by one.
(define (list-insert-at! lis obj k) (define (list-insert-at! lis obj k)
(cond (cond