mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 20:30:28 +02:00
* common-list.scm (uniq): Made tail-recursive. Thanks to thi!
This commit is contained in:
parent
e85da7d990
commit
23d919087e
1 changed files with 8 additions and 7 deletions
|
@ -225,10 +225,11 @@ non-#f return values of P."
|
||||||
|
|
||||||
(define-public (uniq l)
|
(define-public (uniq l)
|
||||||
"Return a list containing elements of L, with duplicates removed."
|
"Return a list containing elements of L, with duplicates removed."
|
||||||
|
(let loop ((acc '())
|
||||||
|
(l l))
|
||||||
(if (null? l)
|
(if (null? l)
|
||||||
'()
|
(reverse! acc)
|
||||||
(let ((u (uniq (cdr l))))
|
(loop (if (memq (car l) acc)
|
||||||
(if (memq (car l) u)
|
acc
|
||||||
u
|
(cons (car l) acc))
|
||||||
(cons (car l) u)))))
|
(cdr l)))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue