1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 20:30:28 +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:48:42 +00:00
parent c581c8eb55
commit df99edbcbe

View file

@ -988,15 +988,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 =)
(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 '()))