1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

(lset-union): Rewrite to accumulate result by consing in

the order specified by the SRFI.
This commit is contained in:
Kevin Ryde 2005-04-01 23:47:42 +00:00
parent 6507b83189
commit 62a8750001

View file

@ -673,15 +673,17 @@
(lp (cdr l) (cons (car l) acc))))))
(define (lset-union = . rest)
(let lp0 ((l rest) (acc '()))
(if (null? l)
(reverse! acc)
(let lp1 ((ll (car l)) (acc acc))
(if (null? ll)
(lp0 (cdr l) acc)
(if (member (car ll) acc (lambda (x y) (= y x)))
(lp1 (cdr ll) acc)
(lp1 (cdr ll) (cons (car ll) acc))))))))
(let ((acc '()))
(for-each (lambda (lst)
(if (null? acc)
(set! acc lst)
(for-each (lambda (elem)
(if (not (member elem acc
(lambda (x y) (= y x))))
(set! acc (cons elem acc))))
lst)))
rest)
acc))
(define (lset-intersection = list1 . rest)
(let lp ((l list1) (acc '()))