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)))))) (lp (cdr l) (cons (car l) acc))))))
(define (lset-union = . rest) (define (lset-union = . rest)
(let lp0 ((l rest) (acc '())) (let ((acc '()))
(if (null? l) (for-each (lambda (lst)
(reverse! acc) (if (null? acc)
(let lp1 ((ll (car l)) (acc acc)) (set! acc lst)
(if (null? ll) (for-each (lambda (elem)
(lp0 (cdr l) acc) (if (not (member elem acc
(if (member (car ll) acc =) (lambda (x y) (= y x))))
(lp1 (cdr ll) acc) (set! acc (cons elem acc))))
(lp1 (cdr ll) (cons (car ll) acc)))))))) lst)))
rest)
acc))
(define (lset-intersection = list1 . rest) (define (lset-intersection = list1 . rest)
(let lp ((l list1) (acc '())) (let lp ((l list1) (acc '()))