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:
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)
|
||||
"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)))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue