implements delete-duplicates(!) tail-recursively

This commit is contained in:
stibear 2014-06-26 22:44:38 +09:00
parent b77fac6ce1
commit 2526474fb3
1 changed files with 325 additions and 325 deletions

View File

@ -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!)