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