implements delete-duplicates(!) tail-recursively
This commit is contained in:
parent
b77fac6ce1
commit
2526474fb3
|
@ -550,23 +550,23 @@
|
|||
|
||||
(define (delete-duplicates list . =)
|
||||
(let ((= (if (null? =) equal? (car =))))
|
||||
(let rec ((list list))
|
||||
(let rec ((list list) (cont values))
|
||||
(if (null? list)
|
||||
list
|
||||
(cont '())
|
||||
(let* ((x (car list))
|
||||
(rest (cdr list))
|
||||
(deleted (rec (delete x list =))))
|
||||
(if (eq? rest deleted) list (cons x deleted)))))))
|
||||
(deleted (delete x rest =)))
|
||||
(rec deleted (lambda (y) (cont (cons x y)))))))))
|
||||
|
||||
(define (delete-duplicates! list . =)
|
||||
(let ((= (if (null? =) equal? (car =))))
|
||||
(let rec ((list list))
|
||||
(let rec ((list list) (cont values))
|
||||
(if (null? list)
|
||||
list
|
||||
(cont '())
|
||||
(let* ((x (car list))
|
||||
(rest (cdr list))
|
||||
(deleted (rec (delete! x list =))))
|
||||
(if (eq? rest deleted) list (cons x deleted)))))))
|
||||
(deleted (delete! x list =)))
|
||||
(rec deleted (lambda (y) (cont (cons x y)))))))))
|
||||
|
||||
(export delete delete-duplicates
|
||||
delete! delete-duplicates!)
|
||||
|
|
Loading…
Reference in New Issue