summaryrefslogtreecommitdiffstats
path: root/srfi/alist-impl.scm
diff options
context:
space:
mode:
authorGravatar Arvydas Silanskas 2021-10-16 11:27:30 +0300
committerGravatar Arvydas Silanskas 2021-10-16 11:27:30 +0300
commit84463b24c49e8333b81567c5e0148b8f4bcd103f (patch)
tree08dd6a3d5ac723e8f8fb8b11d6ee45fa575609b2 /srfi/alist-impl.scm
parentmerge (diff)
work
Diffstat (limited to 'srfi/alist-impl.scm')
-rw-r--r--srfi/alist-impl.scm75
1 files changed, 18 insertions, 57 deletions
diff --git a/srfi/alist-impl.scm b/srfi/alist-impl.scm
index 59fac7b..4400602 100644
--- a/srfi/alist-impl.scm
+++ b/srfi/alist-impl.scm
@@ -1,14 +1,12 @@
(define (make-alist-dtd key=)
- (define (make-alist dtd comparator)
- (when comparator
- (raise (dictionary-error "alist dtd doesn't accept comparator" dtd)))
- '())
-
(define (alist? dtd l)
(and (list? l)
(or (null? l)
(pair? (car l)))))
+
+ (define (alist-mutable? dtd alist)
+ #f)
(define (alist-map dtd proc alist)
(map
@@ -18,76 +16,49 @@
(cons key (proc key value)))
alist))
- (define (alist-map! dtd proc alist)
- (map!
- (lambda (e)
- (define key (car e))
- (define value (cdr e))
- (cons key (proc key value)))
- alist))
-
(define (alist-filter dtd pred alist)
(filter
(lambda (e)
(pred (car e) (cdr e)))
alist))
- (define (alist-filter! dtd pred alist)
- (filter!
- (lambda (e)
- (pred (car e) (cdr e)))
- alist))
-
(define (alist-delete dtd key alist)
(filter
(lambda (entry)
(not (key= (car entry) key)))
alist))
- (define (alist-delete! dtd key alist)
- (filter!
- (lambda (entry)
- (not (key= (car entry) key)))
- alist))
-
- (define (alist-search* dtd alist-delete-proc alist key failure success)
+ (define (alist-alter dtd alist key failure success)
(define (handle-success pair)
(define old-key (car pair))
(define old-value (cdr pair))
- (define (update new-key new-value obj)
+ (define (update new-key new-value)
(cond
((and (eq? old-key
new-key)
(eq? old-value
new-value))
- (values alist obj))
+ alist)
(else
(let ((new-list
(alist-cons
new-key new-value
- (alist-delete-proc dtd old-key alist))))
- (values new-list obj)))))
- (define (remove obj)
- (values (alist-delete-proc dtd old-key alist) obj))
+ (alist-delete dtd old-key alist))))
+ new-list))))
+ (define (remove)
+ (alist-delete dtd old-key alist))
(success old-key old-value update remove))
(define (handle-failure)
- (define (insert value obj)
- (values (alist-cons key value alist)
- obj))
- (define (ignore obj)
- (values alist obj))
+ (define (insert value)
+ (alist-cons key value alist))
+ (define (ignore)
+ alist)
(failure insert ignore))
(cond
((assoc key alist key=) => handle-success)
(else (handle-failure))))
- (define (alist-search dtd alist key failure success)
- (alist-search* dtd alist-delete alist key failure success))
-
- (define (alist-search! dtd alist key failure success)
- (alist-search* dtd alist-delete! alist key failure success))
-
(define (alist-size dtd alist)
(length alist))
@@ -96,32 +67,22 @@
(proc (car e) (cdr e)))
(for-each proc* alist))
- (define (alist-copy dtd alist)
- (map
- (lambda (e)
- (cons (car e) (cdr e)))
- alist))
-
(define (alist->alist dtd alist)
- (alist-copy dtd alist))
+ alist)
(define (alist-comparator dtd dictionary)
#f)
(make-dtd
- make-dictionary-id make-alist
dictionary?-id alist?
+ dict-mutable?-id alist-mutable?
dict-map-id alist-map
- dict-map!-id alist-map!
dict-filter-id alist-filter
- dict-filter!-id alist-filter!
- dict-search-id alist-search
- dict-search!-id alist-search!
+ dict-alter-id alist-alter
dict-size-id alist-size
dict-for-each-id alist-foreach
dict->alist-id alist->alist
- dict-comparator-id alist-comparator
- dict-copy-id alist-copy))
+ dict-comparator-id alist-comparator))
(define alist-eqv-dtd (make-alist-dtd eqv?))
(define alist-equal-dtd (make-alist-dtd equal?))