summaryrefslogtreecommitdiffstats
path: root/comlist.scm
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:28 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:28 -0800
commitbd9733926076885e3417b74de76e4c9c7bc56254 (patch)
tree2c99dced547d48407ad44cb0e45e31bb4d02ce43 /comlist.scm
parentfa3f23105ddcf07c5900de47f19af43d1db1b597 (diff)
downloadslib-bd9733926076885e3417b74de76e4c9c7bc56254.tar.gz
slib-bd9733926076885e3417b74de76e4c9c7bc56254.zip
Import Upstream version 2c7upstream/2c7
Diffstat (limited to 'comlist.scm')
-rw-r--r--comlist.scm22
1 files changed, 16 insertions, 6 deletions
diff --git a/comlist.scm b/comlist.scm
index 1751c7f..8ecf525 100644
--- a/comlist.scm
+++ b/comlist.scm
@@ -31,7 +31,7 @@
(define (comlist:copy-list lst) (append lst '()))
-(define (comlist:adjoin e l) (if (memq e l) l (cons e l)))
+(define (comlist:adjoin e l) (if (memv e l) l (cons e l)))
(define (comlist:union l1 l2)
(cond ((null? l1) l2)
@@ -176,13 +176,22 @@
((car args) #t)
(else (apply comlist:or? (cdr args)))))
-; Checks to see if a list has any duplicates.
+;;; Checks to see if a list has any duplicate MEMBERs.
(define (comlist:has-duplicates? lst)
(cond ((null? lst) #f)
((member (car lst) (cdr lst)) #t)
(else (comlist:has-duplicates? (cdr lst)))))
-(define (comlist:list* x . y)
+;;; remove duplicates of MEMBERs of a list
+(define (comlist:remove-duplicates lst)
+ (letrec ((rem-dup
+ (lambda (lst nlst)
+ (cond ((null? lst) nlst)
+ ((member (car lst) nlst) (rem-dup (cdr lst) nlst))
+ (else (rem-dup (cdr lst) (cons (car lst) nlst)))))))
+ (rem-dup lst '())))
+
+(define (comlist:list* x . y)
(define (list*1 x)
(if (null? (cdr x))
(car x)
@@ -283,7 +292,7 @@
((equal? obj (car list)) (delete (cdr list)))
(else
(set-cdr! list (delete (cdr list)))
- list))))
+ list))))
(define (comlist:delete-if pred list)
(let delete-if ((list list))
@@ -291,7 +300,7 @@
((pred (car list)) (delete-if (cdr list)))
(else
(set-cdr! list (delete-if (cdr list)))
- list))))
+ list))))
(define (comlist:delete-if-not pred list)
(let delete-if ((list list))
@@ -299,7 +308,7 @@
((not (pred (car list))) (delete-if (cdr list)))
(else
(set-cdr! list (delete-if (cdr list)))
- list))))
+ list))))
;;; exports
@@ -330,6 +339,7 @@
(define and? comlist:and?)
(define or? comlist:or?)
(define has-duplicates? comlist:has-duplicates?)
+(define remove-duplicates comlist:remove-duplicates)
(define delete-if-not comlist:delete-if-not)
(define delete-if comlist:delete-if)