1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-11 22:31:12 +02:00

* common-list.scm (uniq): Made tail-recursive. Thanks to thi!

This commit is contained in:
Marius Vollmer 2000-07-23 23:12:02 +00:00
parent e85da7d990
commit 23d919087e

View file

@ -225,10 +225,11 @@ non-#f return values of P."
(define-public (uniq l)
"Return a list containing elements of L, with duplicates removed."
(if (null? l)
'()
(let ((u (uniq (cdr l))))
(if (memq (car l) u)
u
(cons (car l) u)))))
(let loop ((acc '())
(l l))
(if (null? l)
(reverse! acc)
(loop (if (memq (car l) acc)
acc
(cons (car l) acc))
(cdr l)))))