This commit is contained in:
Justin Ethier 2018-12-18 13:19:23 -05:00
parent 10bfe42eff
commit 4ac97adb32

View file

@ -134,9 +134,9 @@ if (acc) {
(define inner-union (define inner-union
(lambda (last l1 l2) (lambda (last l1 l2)
(if (null? l1) (if (null? l1)
l2 ;; TODO: sort l2 (or figure out why we get passed an unsorted list (next last l2)
(if (null? l2) (if (null? l2)
l1 ;; TODO: sort l1 (next last l1)
;; TODO: also have an eq? check to eliminate duplicates ;; TODO: also have an eq? check to eliminate duplicates
(if (symbol<? (car l1) (car l2)) (if (symbol<? (car l1) (car l2))
(if (eq? last (car l1)) (if (eq? last (car l1))
@ -146,6 +146,11 @@ if (acc) {
(inner-union last l1 (cdr l2)) (inner-union last l1 (cdr l2))
(cons (car l2) (inner-union (car l2) l1 (cdr l2))))))))) (cons (car l2) (inner-union (car l2) l1 (cdr l2)))))))))
(define (next sym lis)
(if (and (pair? lis) (eq? sym (car lis)))
(next sym (cdr lis))
lis))
(write (write
(union '(a b c) '(d e f))) (union '(a b c) '(d e f)))
(newline) (newline)