diff options
| author | 2021-11-23 14:21:56 -0500 | |
|---|---|---|
| committer | 2021-11-23 14:21:56 -0500 | |
| commit | a6fbdb2cfe97b41c4479170d80934f218a1553a8 (patch) | |
| tree | b538484cf28d6b09b0cf021529302fc6b4273697 | |
| parent | improved rationale (diff) | |
dto and find-update
| -rw-r--r-- | srfi-225-test.scm | 396 | ||||
| -rw-r--r-- | srfi-225.html | 259 | ||||
| -rw-r--r-- | srfi/225.sld | 44 | ||||
| -rw-r--r-- | srfi/alist-impl.scm | 34 | ||||
| -rw-r--r-- | srfi/default-impl.scm | 270 | ||||
| -rw-r--r-- | srfi/externals.scm | 130 | ||||
| -rw-r--r-- | srfi/indexes.scm | 2 | ||||
| -rw-r--r-- | srfi/srfi-125-impl.scm | 58 | ||||
| -rw-r--r-- | srfi/srfi-126-impl.scm | 54 | ||||
| -rw-r--r-- | srfi/srfi-146-hash-impl.scm | 64 | ||||
| -rw-r--r-- | srfi/srfi-146-impl.scm | 64 | ||||
| -rw-r--r-- | srfi/srfi-69-impl.scm | 46 |
12 files changed, 710 insertions, 711 deletions
diff --git a/srfi-225-test.scm b/srfi-225-test.scm index 3630605..1ef4231 100644 --- a/srfi-225-test.scm +++ b/srfi-225-test.scm @@ -48,19 +48,19 @@ (else (import (srfi 64)))) -;; returns new wrapper dtd -;; which counts how often each dtd's method was called +;; returns new wrapper dto +;; which counts how often each dto's method was called ;; verify that all functions were tested -(define (wrap-dtd dtd) +(define (wrap-dto dto) (define proc-count (+ 1 dict-adjoin-accumulator-id)) (define counter (make-vector proc-count 0)) - (define wrapper-dtd-args + (define wrapper-dto-args (let loop ((indexes (iota proc-count)) (args '())) (if (null? indexes) args (let* ((index (car indexes)) - (real-proc (dtd-ref dtd index)) + (real-proc (dto-ref dto index)) (wrapper-proc (lambda args (vector-set! counter index (+ 1 (vector-ref counter index))) (apply real-proc args)))) @@ -68,7 +68,7 @@ (append (list index wrapper-proc) args)))))) (values - (apply make-dtd wrapper-dtd-args) + (apply make-dto wrapper-dto-args) counter)) (define (test-for-each expect-success for-each-proc expected-keys) @@ -89,28 +89,28 @@ expected-keys))) lst)))))) -(define (do-test real-dtd alist->dict comparator mutable?) +(define (do-test real-dto alist->dict comparator mutable?) (define-values - (dtd counter) - (wrap-dtd real-dtd)) + (dto counter) + (wrap-dto real-dto)) (test-group "dictionary?" - (test-assert (not (dictionary? dtd 'foo))) - (test-assert (dictionary? dtd (alist->dict '()))) - (test-assert (dictionary? dtd (alist->dict '((a . b)))))) + (test-assert (not (dictionary? dto 'foo))) + (test-assert (dictionary? dto (alist->dict '()))) + (test-assert (dictionary? dto (alist->dict '((a . b)))))) (test-group "dict-empty?" - (test-assert (dict-empty? dtd (alist->dict '()))) - (test-assert (not (dict-empty? dtd (alist->dict '((a . b))))))) + (test-assert (dict-empty? dto (alist->dict '()))) + (test-assert (not (dict-empty? dto (alist->dict '((a . b))))))) (test-group "dict-contains?" - (test-assert (not (dict-contains? dtd (alist->dict '()) 'a))) - (test-assert (not (dict-contains? dtd (alist->dict '((b . c))) 'a))) - (test-assert (dict-contains? dtd (alist->dict '((a . b))) 'a))) + (test-assert (not (dict-contains? dto (alist->dict '()) 'a))) + (test-assert (not (dict-contains? dto (alist->dict '((b . c))) 'a))) + (test-assert (dict-contains? dto (alist->dict '((a . b))) 'a))) (test-group "dict=?" @@ -119,108 +119,108 @@ (define dict3 (alist->dict '((a . 1)))) (define dict4 (alist->dict '((a . 2) (b . 2)))) - (test-assert (dict=? dtd = dict1 dict2)) - (test-assert (not (dict=? dtd = dict1 dict3))) - (test-assert (not (dict=? dtd = dict3 dict1))) - (test-assert (not (dict=? dtd = dict1 dict4))) - (test-assert (not (dict=? dtd = dict4 dict1)))) + (test-assert (dict=? dto = dict1 dict2)) + (test-assert (not (dict=? dto = dict1 dict3))) + (test-assert (not (dict=? dto = dict3 dict1))) + (test-assert (not (dict=? dto = dict1 dict4))) + (test-assert (not (dict=? dto = dict4 dict1)))) (test-group "dict-ref" - (test-assert (dict-ref dtd (alist->dict '((a . b))) 'a (lambda () #f) (lambda (x) #t))) - (test-assert (dict-ref dtd (alist->dict '((a . b))) 'b (lambda () #t) (lambda (x) #f)))) + (test-assert (dict-ref dto (alist->dict '((a . b))) 'a (lambda () #f) (lambda (x) #t))) + (test-assert (dict-ref dto (alist->dict '((a . b))) 'b (lambda () #t) (lambda (x) #f)))) (test-group "dict-ref/default" - (test-equal (dict-ref/default dtd (alist->dict '((a . b))) 'a 'c) 'b) - (test-equal (dict-ref/default dtd (alist->dict '((a* . b))) 'a 'c) 'c)) + (test-equal (dict-ref/default dto (alist->dict '((a . b))) 'a 'c) 'b) + (test-equal (dict-ref/default dto (alist->dict '((a* . b))) 'a 'c) 'c)) (when mutable? (test-skip 1)) (test-group "dict-set" (define dict-original (alist->dict '((a . b)))) - (define d (dict-set dtd dict-original 'a 'c 'a2 'b2)) - (test-equal 'c (dict-ref dtd d 'a )) - (test-equal 'b2 (dict-ref dtd d 'a2)) - (test-equal 'b (dict-ref dtd dict-original' a)) - (test-equal #f (dict-ref/default dtd dict-original 'a2 #f))) + (define d (dict-set dto dict-original 'a 'c 'a2 'b2)) + (test-equal 'c (dict-ref dto d 'a )) + (test-equal 'b2 (dict-ref dto d 'a2)) + (test-equal 'b (dict-ref dto dict-original' a)) + (test-equal #f (dict-ref/default dto dict-original 'a2 #f))) (unless mutable? (test-skip 1)) (test-group "dict-set!" - (define d (dict-set! dtd (alist->dict '((a . b))) 'a 'c 'a2 'b2)) - (test-equal 'c (dict-ref dtd d 'a )) - (test-equal 'b2 (dict-ref dtd d 'a2))) + (define d (dict-set! dto (alist->dict '((a . b))) 'a 'c 'a2 'b2)) + (test-equal 'c (dict-ref dto d 'a )) + (test-equal 'b2 (dict-ref dto d 'a2))) (when mutable? (test-skip 1)) (test-group "dict-adjoin" (define dict-original (alist->dict '((a . b)))) - (define d (dict-adjoin dtd dict-original 'a 'c 'a2 'b2)) - (test-equal 'b (dict-ref dtd d 'a)) - (test-equal 'b2 (dict-ref dtd d 'a2)) - (test-equal #f (dict-ref/default dtd dict-original 'a2 #f))) + (define d (dict-adjoin dto dict-original 'a 'c 'a2 'b2)) + (test-equal 'b (dict-ref dto d 'a)) + (test-equal 'b2 (dict-ref dto d 'a2)) + (test-equal #f (dict-ref/default dto dict-original 'a2 #f))) (unless mutable? (test-skip 1)) (test-group "dict-adjoin!" - (define d (dict-adjoin! dtd (alist->dict '((a . b))) 'a 'c 'a2 'b2)) - (test-equal 'b (dict-ref dtd d 'a)) - (test-equal 'b2 (dict-ref dtd d 'a2))) + (define d (dict-adjoin! dto (alist->dict '((a . b))) 'a 'c 'a2 'b2)) + (test-equal 'b (dict-ref dto d 'a)) + (test-equal 'b2 (dict-ref dto d 'a2))) (when mutable? (test-skip 1)) (test-group "dict-delete" (define dict-original (alist->dict '((a . b) (c . d)))) - (define d (dict-delete dtd dict-original 'a 'b)) - (test-equal (dict->alist dtd d) '((c . d))) - (test-equal 'b (dict-ref dtd dict-original 'a))) + (define d (dict-delete dto dict-original 'a 'b)) + (test-equal (dict->alist dto d) '((c . d))) + (test-equal 'b (dict-ref dto dict-original 'a))) (unless mutable? (test-skip 1)) (test-group "dict-delete!" - (define d (dict-delete! dtd (alist->dict '((a . b) (c . d))) 'a 'b)) - (test-equal (dict->alist dtd d) '((c . d)))) + (define d (dict-delete! dto (alist->dict '((a . b) (c . d))) 'a 'b)) + (test-equal (dict->alist dto d) '((c . d)))) (when mutable? (test-skip 1)) (test-group "dict-delete-all" (define dict-original (alist->dict '((a . b) (c . d)))) - (define d (dict-delete-all dtd dict-original '(a b))) - (test-equal (dict->alist dtd d) '((c . d))) - (test-equal 'b (dict-ref dtd dict-original 'a))) + (define d (dict-delete-all dto dict-original '(a b))) + (test-equal (dict->alist dto d) '((c . d))) + (test-equal 'b (dict-ref dto dict-original 'a))) (unless mutable? (test-skip 1)) (test-group "dict-delete-all!" - (define d (dict-delete-all! dtd (alist->dict '((a . b) (c . d))) '(a b))) - (test-equal (dict->alist dtd d) '((c . d)))) + (define d (dict-delete-all! dto (alist->dict '((a . b) (c . d))) '(a b))) + (test-equal (dict->alist dto d) '((c . d)))) (when mutable? (test-skip 1)) (test-group "dict-replace" (define dict-original (alist->dict '((a . b) (c . d)))) - (define d (dict-replace dtd dict-original 'a 'b2)) - (test-equal 'b2 (dict-ref dtd d 'a)) - (test-equal 'd (dict-ref dtd d 'c)) - (test-equal 'b (dict-ref dtd dict-original 'a))) + (define d (dict-replace dto dict-original 'a 'b2)) + (test-equal 'b2 (dict-ref dto d 'a)) + (test-equal 'd (dict-ref dto d 'c)) + (test-equal 'b (dict-ref dto dict-original 'a))) (unless mutable? (test-skip 1)) (test-group "dict-replace!" - (define d (dict-replace! dtd (alist->dict '((a . b) (c . d))) 'a 'b2)) - (test-equal 'b2 (dict-ref dtd d 'a)) - (test-equal 'd (dict-ref dtd d 'c))) + (define d (dict-replace! dto (alist->dict '((a . b) (c . d))) 'a 'b2)) + (test-equal 'b2 (dict-ref dto d 'a)) + (test-equal 'd (dict-ref dto d 'c))) (when mutable? (test-skip 1)) @@ -230,19 +230,19 @@ (let () (define-values (d value) - (dict-intern dtd (alist->dict '((a . b))) 'a (lambda () 'd))) - (test-equal 'b (dict-ref dtd d 'a)) + (dict-intern dto (alist->dict '((a . b))) 'a (lambda () 'd))) + (test-equal 'b (dict-ref dto d 'a)) (test-equal 'b value)) ;; intern missing (let () (define dict-original (alist->dict '((a . b)))) (define-values (d value) - (dict-intern dtd dict-original 'c (lambda () 'd))) - (test-equal 'b (dict-ref dtd d 'a)) - (test-equal 'd (dict-ref dtd d 'c)) + (dict-intern dto dict-original 'c (lambda () 'd))) + (test-equal 'b (dict-ref dto d 'a)) + (test-equal 'd (dict-ref dto d 'c)) (test-equal 'd value) - (test-equal #f (dict-ref/default dtd dict-original 'c #f)))) + (test-equal #f (dict-ref/default dto dict-original 'c #f)))) (unless mutable? (test-skip 1)) @@ -252,16 +252,16 @@ (let () (define-values (d value) - (dict-intern! dtd (alist->dict '((a . b))) 'a (lambda () 'd))) - (test-equal 'b (dict-ref dtd d 'a)) + (dict-intern! dto (alist->dict '((a . b))) 'a (lambda () 'd))) + (test-equal 'b (dict-ref dto d 'a)) (test-equal 'b value)) ;; intern missing (let () (define-values (d value) - (dict-intern! dtd (alist->dict '((a . b))) 'c (lambda () 'd))) - (test-equal 'b (dict-ref dtd d 'a)) - (test-equal 'd (dict-ref dtd d 'c)) + (dict-intern! dto (alist->dict '((a . b))) 'c (lambda () 'd))) + (test-equal 'b (dict-ref dto d 'a)) + (test-equal 'd (dict-ref dto d 'c)) (test-equal 'd value))) (when mutable? @@ -271,22 +271,22 @@ ;; update existing (define dict-original (alist->dict '((a . "b")))) (let () - (define d (dict-update dtd dict-original 'a + (define d (dict-update dto dict-original 'a (lambda (value) (string-append value "2")) error (lambda (x) (string-append x "1")))) - (test-equal "b12" (dict-ref dtd d 'a)) - (test-equal "b" (dict-ref dtd dict-original 'a))) + (test-equal "b12" (dict-ref dto d 'a)) + (test-equal "b" (dict-ref dto dict-original 'a))) ;; update missing (let () - (define d (dict-update dtd dict-original 'c + (define d (dict-update dto dict-original 'c (lambda (value) (string-append value "2")) (lambda () "d1") (lambda (x) (string-append x "1")))) - (test-equal "d12" (dict-ref dtd d 'c)) - (test-equal #f (dict-ref/default dtd dict-original 'c #f)))) + (test-equal "d12" (dict-ref dto d 'c)) + (test-equal #f (dict-ref/default dto dict-original 'c #f)))) (unless mutable? (test-skip 1)) @@ -294,20 +294,20 @@ "dict-update!" ;; update existing (let () - (define d (dict-update! dtd (alist->dict '((a . "b"))) 'a + (define d (dict-update! dto (alist->dict '((a . "b"))) 'a (lambda (value) (string-append value "2")) error (lambda (x) (string-append x "1")))) - (test-equal "b12" (dict-ref dtd d 'a))) + (test-equal "b12" (dict-ref dto d 'a))) ;; update missing (let () - (define d (dict-update! dtd (alist->dict '((a . "b"))) 'c + (define d (dict-update! dto (alist->dict '((a . "b"))) 'c (lambda (value) (string-append value "2")) (lambda () "d1") (lambda (x) (string-append x "1")))) - (test-equal "d12" (dict-ref dtd d 'c)))) + (test-equal "d12" (dict-ref dto d 'c)))) (when mutable? (test-skip 1)) @@ -316,21 +316,21 @@ ;; update existing (define dict-original (alist->dict '((a . "b")))) (let () - (define d (dict-update/default dtd dict-original 'a + (define d (dict-update/default dto dict-original 'a (lambda (value) (string-append value "2")) "d1")) - (test-equal "b2" (dict-ref dtd d 'a)) - (test-equal "b" (dict-ref dtd dict-original 'a))) + (test-equal "b2" (dict-ref dto d 'a)) + (test-equal "b" (dict-ref dto dict-original 'a))) ;; update missing (let () - (define d (dict-update/default dtd dict-original 'c + (define d (dict-update/default dto dict-original 'c (lambda (value) (string-append value "2")) "d1")) - (test-equal "d12" (dict-ref dtd d 'c)) - (test-equal #f (dict-ref/default dtd dict-original 'c #f)))) + (test-equal "d12" (dict-ref dto d 'c)) + (test-equal #f (dict-ref/default dto dict-original 'c #f)))) (unless mutable? (test-skip 1)) @@ -338,19 +338,19 @@ "dict-update/default!" ;; update existing (let () - (define d (dict-update/default! dtd (alist->dict '((a . "b"))) 'a + (define d (dict-update/default! dto (alist->dict '((a . "b"))) 'a (lambda (value) (string-append value "2")) "d1")) - (test-equal "b2" (dict-ref dtd d 'a))) + (test-equal "b2" (dict-ref dto d 'a))) ;; update missing (let () - (define d (dict-update/default! dtd (alist->dict '((a . "b"))) 'c + (define d (dict-update/default! dto (alist->dict '((a . "b"))) 'c (lambda (value) (string-append value "2")) "d1")) - (test-equal "d12" (dict-ref dtd d 'c)))) + (test-equal "d12" (dict-ref dto d 'c)))) (when mutable? (test-skip 1)) @@ -359,18 +359,18 @@ (define dict-original (alist->dict '((a . b) (c . d)))) (define-values (new-dict key value) - (dict-pop dtd dict-original)) + (dict-pop dto dict-original)) (test-assert (or - (and (equal? (dict->alist dtd new-dict) '((c . d))) + (and (equal? (dict->alist dto new-dict) '((c . d))) (equal? key 'a) (equal? value 'b)) - (and (equal? (dict->alist dtd new-dict) '((a . b))) + (and (equal? (dict->alist dto new-dict) '((a . b))) (equal? key 'c) (equal? value 'd)))) - (test-assert 'b (dict-ref dtd dict-original 'a)) - (test-assert 'd (dict-ref dtd dict-original 'c))) + (test-assert 'b (dict-ref dto dict-original 'a)) + (test-assert 'd (dict-ref dto dict-original 'c))) (unless mutable? (test-skip 1)) @@ -378,14 +378,14 @@ "dict-pop!" (define-values (new-dict key value) - (dict-pop! dtd (alist->dict '((a . b) (c . d))))) + (dict-pop! dto (alist->dict '((a . b) (c . d))))) (test-assert (or - (and (equal? (dict->alist dtd new-dict) '((c . d))) + (and (equal? (dict->alist dto new-dict) '((c . d))) (equal? key 'a) (equal? value 'b)) - (and (equal? (dict->alist dtd new-dict) '((a . b))) + (and (equal? (dict->alist dto new-dict) '((a . b))) (equal? key 'c) (equal? value 'd))))) @@ -394,25 +394,25 @@ (test-group "dict-map" (define dict-original (alist->dict '((a . "a") (b . "b")))) - (define d (dict-map dtd + (define d (dict-map dto (lambda (key value) (string-append value "2")) dict-original)) - (test-equal "a2" (dict-ref dtd d 'a)) - (test-equal "b2" (dict-ref dtd d 'b)) - (test-equal "a" (dict-ref dtd dict-original 'a)) - (test-equal "b" (dict-ref dtd dict-original 'b))) + (test-equal "a2" (dict-ref dto d 'a)) + (test-equal "b2" (dict-ref dto d 'b)) + (test-equal "a" (dict-ref dto dict-original 'a)) + (test-equal "b" (dict-ref dto dict-original 'b))) (unless mutable? (test-skip 1)) (test-group "dict-map!" - (define d (dict-map! dtd + (define d (dict-map! dto (lambda (key value) (string-append value "2")) (alist->dict '((a . "a") (b . "b"))))) - (test-equal "a2" (dict-ref dtd d 'a)) - (test-equal "b2" (dict-ref dtd d 'b))) + (test-equal "a2" (dict-ref dto d 'a)) + (test-equal "b2" (dict-ref dto d 'b))) (when mutable? (test-skip 1)) @@ -420,142 +420,142 @@ "dict-filter" (define dict-original (alist->dict '((a . b) (c . d)))) - (define d (dict-filter dtd + (define d (dict-filter dto (lambda (key value) (equal? value 'b)) dict-original)) - (test-equal '((a . b)) (dict->alist dtd d)) - (test-equal 'd (dict-ref dtd dict-original 'c))) + (test-equal '((a . b)) (dict->alist dto d)) + (test-equal 'd (dict-ref dto dict-original 'c))) (unless mutable? (test-skip 1)) (test-group "dict-filter!" - (define d (dict-filter! dtd + (define d (dict-filter! dto (lambda (key value) (equal? value 'b)) (alist->dict '((a . b) (c . d))))) - (test-equal '((a . b)) (dict->alist dtd d))) + (test-equal '((a . b)) (dict->alist dto d))) (when mutable? (test-skip 1)) (test-group "dict-remove" (define dict-original (alist->dict '((a . b) (c . d)))) - (define d (dict-remove dtd + (define d (dict-remove dto (lambda (key value) (equal? value 'b)) dict-original)) - (test-equal '((c . d)) (dict->alist dtd d)) - (test-equal 'b (dict-ref dtd dict-original 'a))) + (test-equal '((c . d)) (dict->alist dto d)) + (test-equal 'b (dict-ref dto dict-original 'a))) (unless mutable? (test-skip 1)) (test-group "dict-remove!" - (define d (dict-remove! dtd + (define d (dict-remove! dto (lambda (key value) (equal? value 'b)) (alist->dict '((a . b) (c . d))))) - (test-equal '((c . d)) (dict->alist dtd d))) + (test-equal '((c . d)) (dict->alist dto d))) (when mutable? (test-skip 1)) (test-group - "dict-alter" + "dict-find-update" ;; ignore (let () - (define dict (dict-alter dtd (alist->dict '((a . b))) 'c + (define dict (dict-find-update dto (alist->dict '((a . b))) 'c (lambda (insert ignore) (ignore)) (lambda args (error "shouldn't happen")))) - (test-equal '((a . b)) (dict->alist dtd dict))) + (test-equal '((a . b)) (dict->alist dto dict))) ;; insert (let () (define dict-original (alist->dict '((a . b)))) - (define dict (dict-alter dtd dict-original 'c + (define dict (dict-find-update dto dict-original 'c (lambda (insert ignore) (insert 'd)) (lambda args (error "shouldn't happen")))) - (test-equal 'b (dict-ref dtd dict 'a)) - (test-equal 'd (dict-ref dtd dict 'c)) - (test-equal #f (dict-ref/default dtd dict-original 'c #f))) + (test-equal 'b (dict-ref dto dict 'a)) + (test-equal 'd (dict-ref dto dict 'c)) + (test-equal #f (dict-ref/default dto dict-original 'c #f))) ;; update (let () (define dict-original (alist->dict '((a . b)))) - (define dict (dict-alter dtd dict-original 'a + (define dict (dict-find-update dto dict-original 'a (lambda args (error "shouldn't happen")) (lambda (key value update delete) (update 'a2 'b2)))) - (test-equal '((a2 . b2)) (dict->alist dtd dict)) - (test-equal #f (dict-ref/default dtd dict-original 'a2 #f)) - (test-equal 'b (dict-ref dtd dict-original 'a))) + (test-equal '((a2 . b2)) (dict->alist dto dict)) + (test-equal #f (dict-ref/default dto dict-original 'a2 #f)) + (test-equal 'b (dict-ref dto dict-original 'a))) ;; delete (let () (define dict-original (alist->dict '((a . b) (c . d)))) - (define dict (dict-alter dtd dict-original 'a + (define dict (dict-find-update dto dict-original 'a (lambda args (error "shouldn't happen")) (lambda (key value update delete) (delete)))) - (test-equal '((c . d)) (dict->alist dtd dict)) - (test-equal 'b (dict-ref dtd dict-original 'a)))) + (test-equal '((c . d)) (dict->alist dto dict)) + (test-equal 'b (dict-ref dto dict-original 'a)))) (unless mutable? (test-skip 1)) (test-group - "dict-alter!" + "dict-find-update!" ;; ignore (let () - (define dict (dict-alter! dtd (alist->dict '((a . b))) 'c + (define dict (dict-find-update! dto (alist->dict '((a . b))) 'c (lambda (insert ignore) (ignore)) (lambda args (error "shouldn't happen")))) - (test-equal '((a . b)) (dict->alist dtd dict))) + (test-equal '((a . b)) (dict->alist dto dict))) ;; insert (let () - (define dict (dict-alter! dtd (alist->dict '((a . b))) 'c + (define dict (dict-find-update! dto (alist->dict '((a . b))) 'c (lambda (insert ignore) (insert 'd)) (lambda args (error "shouldn't happen")))) - (test-equal 'b (dict-ref dtd dict 'a)) - (test-equal 'd (dict-ref dtd dict 'c))) + (test-equal 'b (dict-ref dto dict 'a)) + (test-equal 'd (dict-ref dto dict 'c))) ;; update (let () - (define dict (dict-alter! dtd (alist->dict '((a . b))) 'a + (define dict (dict-find-update! dto (alist->dict '((a . b))) 'a (lambda args (error "shouldn't happen")) (lambda (key value update delete) (update 'a2 'b2)))) - (test-equal '((a2 . b2)) (dict->alist dtd dict))) + (test-equal '((a2 . b2)) (dict->alist dto dict))) ;; delete (let () - (define dict (dict-alter! dtd (alist->dict '((a . b) (c . d))) 'a + (define dict (dict-find-update! dto (alist->dict '((a . b) (c . d))) 'a (lambda args (error "shouldn't happen")) (lambda (key value update delete) (delete)))) - (test-equal '((c . d)) (dict->alist dtd dict)))) + (test-equal '((c . d)) (dict->alist dto dict)))) (test-group "dict-size" - (test-equal 2 (dict-size dtd (alist->dict '((a . b) (c . d))))) - (test-equal 0 (dict-size dtd (alist->dict '())))) + (test-equal 2 (dict-size dto (alist->dict '((a . b) (c . d))))) + (test-equal 0 (dict-size dto (alist->dict '())))) (test-group "dict-count" - (define count (dict-count dtd + (define count (dict-count dto (lambda (key value) (equal? value 'b)) (alist->dict '((a . b) (c . d))))) @@ -566,7 +566,7 @@ (let () (define value - (dict-any dtd + (dict-any dto (lambda (key value) (if (equal? 'b value) 'foo #f)) (alist->dict '((a . b) (c . d))))) @@ -574,7 +574,7 @@ (let () (define value - (dict-any dtd + (dict-any dto (lambda (key value) (if (equal? 'e value) 'foo #f)) (alist->dict '((a . b) (c . d))))) @@ -584,7 +584,7 @@ "dict-every" (let () (define value - (dict-every dtd + (dict-every dto (lambda (key value) (if (equal? 'b value) 'foo #f)) (alist->dict '((a . b) (c . b))))) @@ -592,7 +592,7 @@ (let () (define value - (dict-every dtd + (dict-every dto (lambda (key value) (if (equal? 'b value) 'foo #f)) (alist->dict '()))) @@ -600,7 +600,7 @@ (let () (define value - (dict-every dtd + (dict-every dto (lambda (key value) (if (equal? 'b value) 'foo #f)) (alist->dict '((a . b) (c . d))))) @@ -609,7 +609,7 @@ (test-group "dict-keys" (define keys - (dict-keys dtd (alist->dict '((a . b) (c . d))))) + (dict-keys dto (alist->dict '((a . b) (c . d))))) (test-assert (or (equal? '(a c) keys) (equal? '(c a) keys)))) @@ -617,7 +617,7 @@ (test-group "dict-values" (define vals - (dict-values dtd (alist->dict '((a . b) (c . d))))) + (dict-values dto (alist->dict '((a . b) (c . d))))) (test-assert (or (equal? '(b d) vals) (equal? '(d b) vals)))) @@ -626,7 +626,7 @@ "dict-entries" (define-values (keys vals) - (dict-entries dtd (alist->dict '((a . b) (c . d))))) + (dict-entries dto (alist->dict '((a . b) (c . d))))) (test-assert (or (and (equal? '(a c) keys) (equal? '(b d) vals)) @@ -636,7 +636,7 @@ (test-group "dict-fold" (define value - (dict-fold dtd + (dict-fold dto (lambda (key value acc) (append acc (list key value))) '() @@ -648,7 +648,7 @@ (test-group "dict-map->list" (define lst - (dict-map->list dtd + (dict-map->list dto (lambda (key value) (string-append (symbol->string key) value)) @@ -660,7 +660,7 @@ (test-group "dict->alist" (define alist - (dict->alist dtd (alist->dict '((a . b) (c . d))))) + (dict->alist dto (alist->dict '((a . b) (c . d))))) (test-assert (or (equal? '((a . b) (c . d)) alist) (equal? '((c . d) (a . b)) alist)))) @@ -668,8 +668,8 @@ (test-group "dict-comparator" ;; extremelly basic generic test; more useful specific tests defined separately - ;; for each dtd - (let ((cmp (dict-comparator dtd (alist->dict '((a . b)))))) + ;; for each dto + (let ((cmp (dict-comparator dto (alist->dict '((a . b)))))) (test-assert (or (not cmp) (comparator? cmp))))) @@ -677,7 +677,7 @@ "dict-for-each" (test-for-each #t (lambda (proc) - (dict-for-each dtd + (dict-for-each dto proc (alist->dict '((1 . a) (2 . b) @@ -687,11 +687,11 @@ (test-group "dict-for-each<" - (test-for-each (let* ((cmp (dict-comparator dtd (alist->dict '()))) + (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '()))) (ordering (and cmp (comparator-ordered? cmp)))) ordering) (lambda (proc) - (dict-for-each< dtd + (dict-for-each< dto proc (alist->dict '((1 . a) (2 . b) @@ -702,11 +702,11 @@ (test-group "dict-for-each<=" - (test-for-each (let* ((cmp (dict-comparator dtd (alist->dict '()))) + (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '()))) (ordering (and cmp (comparator-ordered? cmp)))) ordering) (lambda (proc) - (dict-for-each<= dtd + (dict-for-each<= dto proc (alist->dict '((1 . a) (2 . b) @@ -717,11 +717,11 @@ (test-group "dict-for-each>" - (test-for-each (let* ((cmp (dict-comparator dtd (alist->dict '()))) + (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '()))) (ordering (and cmp (comparator-ordered? cmp)))) ordering) (lambda (proc) - (dict-for-each> dtd + (dict-for-each> dto proc (alist->dict '((1 . a) (2 . b) @@ -732,11 +732,11 @@ (test-group "dict-for-each>=" - (test-for-each (let* ((cmp (dict-comparator dtd (alist->dict '()))) + (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '()))) (ordering (and cmp (comparator-ordered? cmp)))) ordering) (lambda (proc) - (dict-for-each>= dtd + (dict-for-each>= dto proc (alist->dict '((1 . a) (2 . b) @@ -747,11 +747,11 @@ (test-group "dict-for-each-in-open-interval" - (test-for-each (let* ((cmp (dict-comparator dtd (alist->dict '()))) + (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '()))) (ordering (and cmp (comparator-ordered? cmp)))) ordering) (lambda (proc) - (dict-for-each-in-open-interval dtd + (dict-for-each-in-open-interval dto proc (alist->dict '((1 . a) (2 . b) @@ -762,11 +762,11 @@ (test-group "dict-for-each-in-closed-interval" - (test-for-each (let* ((cmp (dict-comparator dtd (alist->dict '()))) + (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '()))) (ordering (and cmp (comparator-ordered? cmp)))) ordering) (lambda (proc) - (dict-for-each-in-closed-interval dtd + (dict-for-each-in-closed-interval dto proc (alist->dict '((1 . a) (2 . b) @@ -777,11 +777,11 @@ (test-group "dict-for-each-in-open-closed-interval" - (test-for-each (let* ((cmp (dict-comparator dtd (alist->dict '()))) + (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '()))) (ordering (and cmp (comparator-ordered? cmp)))) ordering) (lambda (proc) - (dict-for-each-in-open-closed-interval dtd + (dict-for-each-in-open-closed-interval dto proc (alist->dict '((1 . a) (2 . b) @@ -792,11 +792,11 @@ (test-group "dict-for-each-in-closed-open-interval" - (test-for-each (let* ((cmp (dict-comparator dtd (alist->dict '()))) + (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '()))) (ordering (and cmp (comparator-ordered? cmp)))) ordering) (lambda (proc) - (dict-for-each-in-closed-open-interval dtd + (dict-for-each-in-closed-open-interval dto proc (alist->dict '((1 . a) (2 . b) @@ -812,26 +812,26 @@ (generator-for-each (lambda (entry) (proc (car entry) (cdr entry))) - (make-dict-generator dtd (alist->dict '((1 . a) + (make-dict-generator dto (alist->dict '((1 . a) (2 . b) (3 . c)))))) '(1 2 3))) (test-group "dict-set-accumulator" - (define acc (dict-set-accumulator dtd (alist->dict '()))) + (define acc (dict-set-accumulator dto (alist->dict '()))) (acc (cons 1 'a)) (acc (cons 2 'b)) (acc (cons 2 'c)) - (test-assert (dict=? dtd equal? (acc (eof-object)) (alist->dict '((1 . a) (2 . c)))))) + (test-assert (dict=? dto equal? (acc (eof-object)) (alist->dict '((1 . a) (2 . c)))))) (test-group "dict-adjoin-accumulator" - (define acc (dict-adjoin-accumulator dtd (alist->dict '()))) + (define acc (dict-adjoin-accumulator dto (alist->dict '()))) (acc (cons 1 'a)) (acc (cons 2 'b)) (acc (cons 2 'c)) - (test-assert (dict=? dtd equal? (acc (eof-object)) (alist->dict '((1 . a) (2 . b)))))) + (test-assert (dict=? dto equal? (acc (eof-object)) (alist->dict '((1 . a) (2 . b)))))) ;; check all procs were called (for-each @@ -845,17 +845,17 @@ (test-group "default" ;; test defaults by overring only procedures that raise error otherwise - (define alist-dtd (make-alist-dtd equal?)) - (define minimal-alist-dtd - (make-dtd - dictionary?-id (dtd-ref alist-dtd dictionary?-id) - dict-mutable?-id (dtd-ref alist-dtd dict-mutable?-id) - dict-size-id (dtd-ref alist-dtd dict-size-id) - dict-alter-id (dtd-ref alist-dtd dict-alter-id) - dict-for-each-id (dtd-ref alist-dtd dict-for-each-id) - dict-comparator-id (dtd-ref alist-dtd dict-comparator-id))) + (define alist-dto (make-alist-dto equal?)) + (define minimal-alist-dto + (make-dto + dictionary?-id (dto-ref alist-dto dictionary?-id) + dict-mutable?-id (dto-ref alist-dto dict-mutable?-id) + dict-size-id (dto-ref alist-dto dict-size-id) + dict-find-update-id (dto-ref alist-dto dict-find-update-id) + dict-for-each-id (dto-ref alist-dto dict-for-each-id) + dict-comparator-id (dto-ref alist-dto dict-comparator-id))) (do-test - minimal-alist-dtd + minimal-alist-dto alist-copy #f #f)) @@ -863,7 +863,7 @@ (test-group "alist" (do-test - (make-alist-dtd equal?) + (make-alist-dto equal?) ;; copy to a mutable list instead of using identity function ;; so that mutating procedures don't fail alist-copy @@ -872,7 +872,7 @@ (test-group "alist dict-comparator" - (test-assert (not (dict-comparator alist-equal-dtd '()))))) + (test-assert (not (dict-comparator alist-equal-dto '()))))) (cond-expand ((and (library (srfi 69)) @@ -881,7 +881,7 @@ (test-group "srfi-69" (do-test - srfi-69-dtd + srfi-69-dto (lambda (alist) (define table (t69-make-hash-table equal?)) (for-each @@ -898,7 +898,7 @@ (test-group "srfi-125 mutable" (do-test - hash-table-dtd + hash-table-dto (lambda (alist) (define table (t125-hash-table-empty-copy (t125-make-hash-table equal?))) (for-each @@ -911,7 +911,7 @@ (test-group "srfi-125 immutable" (do-test - hash-table-dtd + hash-table-dto (lambda (alist) (define table (t125-hash-table-empty-copy (t125-make-hash-table equal?))) (for-each @@ -928,7 +928,7 @@ (test-group "srfi-126 (r6rs) mutable" (do-test - srfi-126-dtd + srfi-126-dto (lambda (alist) (define table (t126-make-eqv-hashtable)) (for-each @@ -941,7 +941,7 @@ (test-group "srfi-126 (r6rs) immutable" (do-test - srfi-126-dtd + srfi-126-dto (lambda (alist) (define table (t126-make-eqv-hashtable)) (for-each @@ -960,7 +960,7 @@ "srfi-146" (define cmp (make-default-comparator)) (do-test - mapping-dtd + mapping-dto (lambda (alist) (let loop ((table (mapping cmp)) (entries alist)) @@ -972,13 +972,13 @@ #f) (test-group "srfi-146 dict-comparator" - (test-equal cmp (dict-comparator mapping-dtd (mapping cmp))))) + (test-equal cmp (dict-comparator mapping-dto (mapping cmp))))) (test-group "srfi-146 hash" (define cmp (make-default-comparator)) (do-test - hash-mapping-dtd + hash-mapping-dto (lambda (alist) (let loop ((table (hashmap cmp)) (entries alist)) @@ -990,7 +990,7 @@ #f) (test-group "srfi-146 hash dict-comparator" - (test-equal cmp (dict-comparator hash-mapping-dtd (hashmap cmp)))))) + (test-equal cmp (dict-comparator hash-mapping-dto (hashmap cmp)))))) (else)) (test-end) diff --git a/srfi-225.html b/srfi-225.html index 3e94c34..5a6799c 100644 --- a/srfi-225.html +++ b/srfi-225.html @@ -29,14 +29,7 @@ <h2 id="abstract">Abstract</h2> -<p>The procedures of this SRFI allow callers to -manipulate an object that maps keys to values -without the caller needing to know exactly what the type -of the object is. -However, what procedures can be called on the dictionary -is partly determined by whether it is pure or not. -Such an object is called a <em>dict</em> in this SRFI. - +<p>The procedures of this SRFI allow callers to manipulate an object that maps keys to values without the caller needing to know exactly what the type of the object is. However, what procedures can be called on the object is partly determined by whether it is pure or not. Such an object is called a <em>dict(ionary)</em> in this SRFI. <h2 id="issues">Issues</h2> None at present. @@ -44,100 +37,105 @@ None at present. <h2 id="rationale">Rationale</h2> <p>Until recently there was only one universally available mechanism for managing key-value pairs: alists. Most Schemes also support hash tables, but until R6RS there was no standard interface to them, and many implementations do not provide that interface.</p> -<p>Now, however, the number of such mechanisms is growing. In addition to both R6RS and R7RS hash tables, there are R7RS persistent ordered and hashed mappings from SRFI 146, ordered mappings with fixnum keys from SRFI 224, and ordered bytevector key-value stores (often on a disk or a remote machine) from SRFI 167.</p> -<p>It’s inconvenient for users if SRFIs or other libraries have to insist on accepting only a specific type of dictionary. This SRFI exposes a number of accessors, updaters, and other procedures that can be called on any dictionary, provided that a <em>dictionary type descriptor</em> (DTD, with apologies to SGML and XML users) is available for it: either exported from this SRFI, or from other SRFIs or libraries, or created by the user. DTDs are of an unspecified type.</p> -<p>This in turn requires that the DTD provides a predicate that can recognize its dictionaries, plus several primitive generic procedures.</p> -<p>By using the procedures of this SRFI, a procedure can take a DTD and a dictionary as an argument and make flexible use of the dictionary without knowing its exact type. For the purposes of this SRFI, such a procedure is called a <em>generic procedure</em>. However, it is still necessary to distinguish between pure and impure dictionary types. A pure dictionary type either exposes pure functional update operations or no update operations at all, whereas an impure dictionary type exposes mutation operations. Note that if an instance of an impure dictionary type like SRFI 126 is in fact immutable, it still counts as impure. -<p>The <code>dict-pure?</code> procedure depends only on the <em>dtd</em> argument and ignores the <i>dict</i> argument except for possibly checking that the arguments taken together satisfy <code>dictionary?</code>. This is done to maintain uniformity between <i>dict-pure?</i> and the other generic procedures, both at the point of call and when <i>make-dtd</i>is invoked.</p> +<p>Now, however, the number of such mechanisms is growing. In addition to both R6RS and R7RS hash tables, there are R7RS persistent inherently ordered and hashed mappings from SRFI 146, inherently ordered mappings with fixnum keys from SRFI 224, and inherently ordered bytevector key-value stores (often on a disk or a remote machine) from SRFI 167.</p> +<p>It’s inconvenient for users if SRFIs or other libraries have to insist on accepting only a specific type of dictionary. This SRFI exposes a number of accessors, updaters, and other procedures that can be called on any dictionary, provided that a <em>dictionary type object</em> (DTO) is available for it: either exported from this SRFI, or from other SRFIs or libraries, or created by the user. DTOs are of an unspecified type.</p> +<p>This in turn requires that the DTO provides a predicate that can recognize its dictionaries, plus several primitive generic procedures.</p> +<p>By using the procedures of this SRFI, a procedure can take a DTO and a dictionary as an argument and make flexible use of the dictionary without knowing its exact type. For the purposes of this SRFI, such a procedure is called a <em>generic procedure</em>. However, it is still necessary to distinguish between pure and impure dictionary types. A pure dictionary type either exposes pure functional update operations or no update operations at all, whereas an impure dictionary type exposes mutation operations. Note that if an instance of an impure dictionary type like SRFI 126 is in fact immutable, it still counts as impure. +<p>The <code>dict-pure?</code> procedure depends only on the <em>dto</em> argument and ignores the <i>dict</i> argument except for possibly checking that the arguments taken together satisfy <code>dictionary?</code>. This is done to maintain uniformity between <i>dict-pure?</i> and the other generic procedures, both at the point of call and when <i>make-dto</i> is invoked.</p> <p>In addition, dictionaries need to be constructed using type-specific constructors, as the required and optional arguments differ in each case. In addition, the dictionary type provided by the caller of a generic procedure doesn't necessarily have the right performance characteristics needed by the generic procedure itself. Consequently there are no <code>make-dict</code>, <code>dict</code>, <code>dict-unfold</code>, <code>dict-copy</code>, or similar procedures provided by this SRFI.</p> <h2 id="specification">Specification</h2> <p>We call a specific key-value combination an <em>association</em>. This is why an alist, or association list, is called that; it is a list of associations represented as pairs.</p> -<p>A <em>dictionary</em> or <em>dict</em> is a collection of associations which may be ordered or unordered. In principle an <em>equality predicate</em> is enough, given a key, to determine whether an association with that key exists in the dictionary. However, for efficiency most dictionaries require an <em>ordering predicate</em> or a <em>hash function</em> as well. -<p>When a key argument is said to be the same as some key of the dictionary, it means that they are the same in the sense of the dictionary’s implicit or explicit equality predicate. It is assumed that no dictionary contains two keys that are the same in this sense. +<p>A <em>dictionary</em> or <em>dict</em> is a collection of associations which may be inherently ordered by their keys or not. In principle an <em>equality predicate</em> is enough, given a key, to determine whether an association with that key exists in the dictionary. However, for efficiency most dictionaries require an <em>ordering predicate</em> or a <em>hash function</em> as well. +<p>When a key argument is said to be the <em>same</em> as some key of the dictionary, it means that they are the same in the sense of the dictionary’s implicit or explicit equality predicate. Two dictionaries are <em>similar</em> if they are of the same type and have the same equality predicate and the same ordering predicate and/or hash function.</p> +<p>When an association is deleted from a dictionary other than by <code>dict-remove</code>, or is updated, any other associations with the same key remain in the dictionary. Whether such duplicate keys are possible depends on the dictionary type. Alists do allow them:</p> +<blockquote><pre>(dict-delete '((1 . 2) (1 . 3) (2 . 4)) 1) => ((1 . 3) (2 . 4))</code>. +</pre></blockquote> <h3 id="alists">Alists</h3> -<p>Alists are supported as dictionaries, but are given special treatment. New values are added to the beginning of the alist and the new alist is returned. If an association has been updated, then both the new and the old association may be processed by the whole-dictionary procedures; by the same token, if an association is removed, any later association with the same key will be exposed. The examples in this SRFI use alists.</p> -<p>An alist (unlike a hashtable or mapping) does not know which equality predicate its users intend to use on it. Therefore, rather than exporting a single DTD for all alists, this SRFI provides a procedure <code>make-alist-dtd</code> that takes an equality predicate and returns a DTD specialized for manipulation of alists using that predicate. For convenience, DTDs for <code>eqv?</code> and <code>equal?</code> are exported.</p> +<p>Alists are supported as dictionaries, but are given special treatment. New values are added to the beginning of the alist and the new alist is returned. If an association has been updated, then both the new and the old association may be processed by the whole-dictionary procedures. The examples in this SRFI use alists.</p> +<p>An alist (unlike a hashtable or mapping) does not know which equality predicate its users intend to use on it. Therefore, rather than exporting a single DTO for all alists, this SRFI provides a procedure <code>make-alist-dto</code> that takes an equality predicate and returns a DTO specialized for manipulation of alists using that predicate. For convenience, DTOs for <code>eqv?</code> and <code>equal?</code> are exported.</p> <p>Each of the following examples is assumed to be prefixed by the following definitions:</p> <blockquote><pre>(define dict (list '(1 . 2) '(3 . 4) '(5 . 6))) -(define aed alist-eqv-dtd) +(define aed alist-eqv-dto) </pre></blockquote> Consequently, previous examples don't affect later ones. -<p>The <em>dtd</em> argument is not discussed in the individual procedure descriptions below, but it is an error if invoking <code>dictionary?</code> on <em>dtd</em> and <em>dict</em> would return <code>#f</code>. The <code>dictionary?</code> procedure itself is an exception to this.</p> +<p>The <em>dto</em> argument is not discussed in the individual procedure descriptions below, but it is an error if invoking <code>dictionary?</code> on <em>dto</em> and <em>dict</em> would return <code>#f</code>. The <code>dictionary?</code> procedure itself is an exception to this.</p> <h3 id="predicates">Predicates</h3> -<p><code>(dictionary?</code> <em>dtd obj</em><code>)</code></p> -<p>Returns <code>#t</code> if <em>obj</em> answers <code>#t</code> to the type predicate stored in <em>dtd</em> and <code>#f</code> otherwise.</p> +<p><code>(dictionary?</code> <em>dto obj</em><code>)</code></p> +<p>Returns <code>#t</code> if <em>obj</em> answers <code>#t</code> to the type predicate stored in <em>dto</em> and <code>#f</code> otherwise.</p> <blockquote><pre>(dictionary? aed dict) => #t (dictionary? aed 35) => #t</pre></blockquote> -<p><code>(dict-empty?</code> <em>dtd dict</em><code>)</code></p> +<p><code>(dict-empty?</code> <em>dto dict</em><code>)</code></p> <p>Returns <code>#t</code> if <em>dict</em> contains no associations and <code>#f</code> if it does contain associations.</p> <blockquote><pre>(dict-empty? aed '()) => #t (dict-empty? aed dict) => #f</pre></blockquote> -<p><code>(dict-contains?</code> <em>dtd dict key</em><code>)</code></p> +<p><code>(dict-contains?</code> <em>dto dict key</em><code>)</code></p> <blockquote><pre>(dict-contains? aed dict 1) => #t (dict-contains? aed dict 2) => #f</pre></blockquote> <p>Returns <code>#t</code> if one of the keys of <em>dict</em> is the same as <em>key</em>, and <code>#f</code> otherwise.</p> -<p><code>(dict=?</code> <em>dtd = dict1 dict2</em><code>)</code></p> -<p>Returns <code>#t</code> if the keys of <em>dtd dict1</em> and <em>dict2</em> are the same, and the corresponding values are the same in the sense of the <em>=</em> argument.</p> +<p><code>(dict=?</code> <em>dto = dict1 dict2</em><code>)</code></p> +<p>Returns <code>#t</code> if the keys of <em>dto dict1</em> and <em>dict2</em> are the same, and the corresponding values are the same in the sense of the <em>=</em> argument.</p> <blockquote><pre> (define dicta '((5 . 6) (3 . 4) (1 . 2)) (define dictb '((1 . 2) (3 . 4)) (dict=? aed = dict dicta) => #t (dict=? aed = dict dictb) => #f</pre></blockquote> -<p><code>(dict-pure?</code> <em>dtd dict</em><code>)</code></p> +<p><code>(dict-pure?</code> <em>dto dict</em><code>)</code></p> <p>Returns <code>#t</code> if the dictionary type is pure and <code>#f</code> otherwise.</p> <blockquote><pre> -(dict-pure? hash-table-dtd (make-hash-table)) => #f +(dict-pure? hash-table-dto (make-hash-table)) => #f (dict-pure? aed dict) => #t </pre></blockquote> <h3 id="lookup">Lookup</h3> -<p><code>(dict-ref</code> <em>dtd dict key</em> [<em>failure</em> [<em>success</em>] ]<code>)</code></p> +<p><code>(dict-ref</code> <em>dto dict key</em> [<em>failure</em> [<em>success</em>] ]<code>)</code></p> <p>If <em>key</em> is the same as some key of <em>dict</em>, then invokes <em>success</em> on the corresponding value and returns its result. If <em>key</em> is not a key of <em>dict</em>, then invokes the thunk <em>failure</em> and returns its result. The default value of <em>failure</em> signals an error; the default value of <em>success</em> is the identity procedure.</p> <blockquote><pre>(dict-ref aed dict 1 (lambda () '()) list) => (1) ; Success wraps value in a list (dict-ref aed dict 2 (lambda () '()) list) => () ; Failure returns empty list</pre></blockquote> -<p><code>(dict-ref/default</code> <em>dtd dict key default</em><code>)</code></p> +<p><code>(dict-ref/default</code> <em>dto dict key default</em><code>)</code></p> <p>If <em>key</em> is the same as some key of <em>dict</em>, returns the corresponding value. If not, returns <em>default</em>.</p> <blockquote><pre>(dict-ref/default aed dict 1 #f) => 1 (dict-ref/default aed dict 1 #f) => #f</pre></blockquote> <h3 id="update-procedures">Update procedures</h3> <p>All update procedures exist in pairs, with and without a final <code>!</code>. The descriptions apply to the procedures without <code>!</code>; the procedures with <code>!</code> mutate their dictionary argument and do not return a dictionary value. Only one set of procedures is supported by any dictionary type: for example, SRFI 125 hash tables are impure and support only mutation, whereas SRFI 146 mappings are pure and support only functional update. The <code>dict-pure?</code> procedure can be used to determine which set is usable.</p> -<p><code>(dict-set</code> <em>dtd dict obj</em> …<code>)</code><br> -<code>(dict-set!</code> <em>dtd dict obj</em> …<code>)</code></p> -<p>Returns a dictionary that contains all the associations of <em>dict</em> plus those specified by <em>objs</em>, which alternate between keys and values. If a key to be added already exists in <em>dict</em>, the new value prevails.</p> +<p><code>(dict-set</code> <em>dto dict obj</em> …<code>)</code><br> +<code>(dict-set!</code> <em>dto dict obj</em> …<code>)</code></p> +<p>Returns a dictionary that contains all the associations of <em>dict</em> plus those specified by <em>objs</em>, which find-updatenate between keys and values. If a key to be added already exists in <em>dict</em>, the new value prevails.</p> <blockquote><pre>; new values are prepended (dict-set aed dict 7 8) => ((7 . 8) (1 . 2) (3 . 4) (5 . 6)) (dict-set aed dict 3 5) => ((3 . 5) (1 . 2) (3 . 4) (5 . 6))</pre></blockquote> -<p><code>(dict-adjoin</code> <em>dtd dict objs</em><code>)</code><br> -<code>(dict-adjoin!</code> <em>dtd dict objs</em><code>)</code></p> -<p>Returns a dictionary that contains all the associations of <em>dict</em> plus those specified by <em>objs</em>, which alternate between keys and values. If a key to be added already exists in <em>dict</em>, the old value prevails.</p> +<p><code>(dict-adjoin</code> <em>dto dict objs</em><code>)</code><br> +<code>(dict-adjoin!</code> <em>dto dict objs</em><code>)</code></p> +<p>Returns a dictionary that contains all the associations of <em>dict</em> plus those specified by <em>objs</em>, which find-updatenate between keys and values. If a key to be added already exists in <em>dict</em>, the old value prevails.</p> <blockquote><pre>; new values are prepended to alists (dict-adjoin aed dict 7 8) => ((7 . 8) (1 . 2) (3 . 4) (5 . 6)) (dict-adjoin aed dict 3 5) => ((1 . 2) (3 . 4) (5 . 6))</pre></blockquote> -<p><code>(dict-delete</code> <em>dtd dict key</em> …<code>)</code><br> -<code>(dict-delete!</code> <em>dtd dict key</em> …<code>)</code></p> -<p>Returns a dictionary that contains all the associations of <em>dict</em> except those whose keys are the same as one of the <em>keys</em>.</p> +<p><code>(dict-delete</code> <em>dto dict key</em> …<code>)</code><br> +<code>(dict-delete!</code> <em>dto dict key</em> …<code>)</code></p> +<p>Returns a dictionary that contains all the associations of <em>dict</em> except those whose keys are the same as one of the <em>keys</em>. <blockquote><pre>; new values are prepended (dict-delete aed dict 1 3) => ((5. 6)) ; may share (dict-delete aed dict 5) => ((1 . 2) (3 . 4))</pre></blockquote> -<p><code>(dict-delete-all</code> <em>dtd dict keylist</em><code>)</code><br> -<code>(dict-delete-all!</code> <em>dtd dict keylist</em><code>)</code></p> -<p>Returns a dictionary with all the associations of <em>dict</em> except those whose keys are the same as some member of <em>keylist</em>.</p> +<p><code>(dict-delete-all</code> <em>dto dict keylist</em><code>)</code><br> +<code>(dict-delete-all!</code> <em>dto dict keylist</em><code>)</code></p> +<p>The same as <code>dict-delete</code>, except that the keys to be deleted are in the list <em>keylist</em>.</p> <blockquote><pre>(dict-delete-all aed dict '(1 3)) => ((5 . 6))</pre></blockquote> -<p><code>(dict-replace</code> <em>dtd dict key value</em><code>)</code><br> -<code>(dict-replace!</code> <em>dtd dict key value</em><code>)</code></p> -<p>Returns a dictionary that contains all the associations of <em>dict</em> except as follows: If <em>key</em> is the same as a key of <em>dict</em>, then the association for that key is omitted and replaced by the association defined by the pair <em>key</em> and <em>value</em>. If there is no such key in <em>dict</em>, then dictionary is returned unchanged.</p> +<p><code>(dict-replace</code> <em>dto dict key value</em><code>)</code><br> +<code>(dict-replace!</code> <em>dto dict key value</em><code>)</code></p> +<p>Returns a dictionary that contains all the associations of <em>dict</em> except as follows: +If <em>key</em> is the same as a key of <em>dict</em>, then the association for that key is omitted and replaced by the association defined by the pair <em>key</em> and <em>value</em>. +If there is no such key in <em>dict</em>, then dictionary is returned unchanged.</p> <blockquote><pre>(dict-replace aed dict 1 3) => ((1 . 3) (1 . 2) (3 . 4) (5 . 6)) </pre></blockquote> -<p><code>(dict-intern</code> <em>dtd dict key failure</em>)<br> -<code>(dict-intern!</code> <em>dtd dict key failure</em>)</p> +<p><code>(dict-intern</code> <em>dto dict key failure</em>)<br> +<code>(dict-intern!</code> <em>dto dict key failure</em>)</p> <p>If there is a key in <em>dict</em> that is the same as <em>key</em>, returns two values, <em>dict</em> and the value associated with <em>key</em>. Otherwise, returns two values, a dictionary that contains all the associations of <em>dict</em> and in addition a new association that maps <em>key</em> to the result of invoking <em>failure</em>, and the result of invoking <em>failure</em>.<br> <blockquote><pre>(dict-intern aed dict 1 (lambda () #f)) => ; 2 values @@ -146,8 +144,8 @@ Otherwise, returns two values, a dictionary that contains all the associations o (dict-intern aed dict 2 (lambda () #f)) => ; 2 values ((2 . #f) (1 . 2) (3 . 4) (5 . 6)) #f</pre></blockquote> -<p><code>(dict-update</code> <em>dtd dict key updater</em> [<em>failure</em> [<em>success</em>] ]<code>)</code><br> -<code>(dict-update!</code> <em>dtd dict key updater</em> [<em>failure</em> [<em>success</em>] ]<code>)</code></p> +<p><code>(dict-update</code> <em>dto dict key updater</em> [<em>failure</em> [<em>success</em>] ]<code>)</code><br> +<code>(dict-update!</code> <em>dto dict key updater</em> [<em>failure</em> [<em>success</em>] ]<code>)</code></p> <p>Retrieves the value of <em>key</em> as if by <code>dict-ref</code>, invokes <em>updater</em> on it, and sets the value of <em>key</em> to be the result of calling <em>updater</em> as if by <code>dict-set</code>, but may do so more efficiently. Returns the updated dictionary. The default value of <em>failure</em> signals an error; the default value of <em>success</em> is the identity procedure.</p> <blockquote><pre> (dict-update aed dict 1 (lambda (x) (+ 1 x))) => @@ -155,8 +153,8 @@ Otherwise, returns two values, a dictionary that contains all the associations o (dict-update aed dict 2 (lambda (x) (+ 1 x))) => <em>error</em> </pre></blockquote> -<p><code>(dict-update/default</code> <em>dtd dict key updater default</em><code>)</code><br> -<code>(dict-update/default!</code> <em>dtd dict key updater default</em><code>)</code></p> +<p><code>(dict-update/default</code> <em>dto dict key updater default</em><code>)</code><br> +<code>(dict-update/default!</code> <em>dto dict key updater default</em><code>)</code></p> <p>Retrieves the value of <em>key</em> as if by <code>dict-ref/default</code>, invokes <em>updater</em> on it, and sets the value of <em>key</em> to be the result of calling <em>updater</em> as if by <code>dict-set</code>, but may do so more efficiently. Returns the updated dictionary.</p> <blockquote><pre> (dict-update/default aed dict 1 @@ -166,46 +164,47 @@ Otherwise, returns two values, a dictionary that contains all the associations o (lambda (x) (+ 1 x)) 0) => ((1 0) (1 2) (3 4) (5 6)) </pre></blockquote> -<p><code>(dict-pop</code> <em>dtd dict</em><code>)</code><br> -<code>(dict-pop!</code> <em>dtd dict</em><code>)</code></p> -<p>Chooses an association from <em>dict</em> and returns three values: a dictionary that contains all associations of <em>dict</em> except the chosen one, and the key and the value of the association chosen. If the dictionary is ordered, the first association is chosen; otherwise the chosen association is arbitrary.</p> +<p><code>(dict-pop</code> <em>dto dict</em><code>)</code><br> +<code>(dict-pop!</code> <em>dto dict</em><code>)</code></p> +<p>Chooses an association from <em>dict</em> and returns three values: a dictionary that contains all associations of <em>dict</em> except the chosen one, and the key and the value of the association chosen. If the dictionary is inherently ordered, the first association is chosen; otherwise the chosen association is arbitrary.</p> <p>If dictionary contains no associations, it is an error.</p> <blockquote><pre>(dict-pop aed dict) => ; 3 values ((3 . 4) (5 . 6)) 1 2</pre></blockquote> -<p><code>(dict-map</code> <em>dtd proc dict</em><code>)</code><br> -<code>(dict-map!</code> <em>dtd proc dict</em><code>)</code></p> +<p><code>(dict-map</code> <em>dto proc dict</em><code>)</code><br> +<code>(dict-map!</code> <em>dto proc dict</em><code>)</code></p> <p>Returns a dictionary similar to <em>dict</em> that maps each key of <em>dict</em> to the <em>proc</em> on the key and corresponding value of <em>dict</em>.</p> <blockquote><pre>(dict-map (lambda (k v) (cons v k)) aed dict) => ((2 . 1) (4 . 3) (6 . 5))</pre></blockquote> -<p><code>(dict-filter</code> <em>dtd pred dict</em><code>)</code><br> -<code>(dict-filter!</code> <em>dtd pred dict</em><code>)</code><br> -<code>(dict-remove</code> <em>dtd pred dict</em><code>)</code><br> -<code>(dict-remove!</code> <em>dtd pred dict</em><code>)</code></p> +<p><code>(dict-filter</code> <em>dto pred dict</em><code>)</code><br> +<code>(dict-filter!</code> <em>dto pred dict</em><code>)</code><br> +<code>(dict-remove</code> <em>dto pred dict</em><code>)</code><br> +<code>(dict-remove!</code> <em>dto pred dict</em><code>)</code></p> <p>Returns a dictionary similar to <em>dict</em> that contains just the associations of <em>dict</em> that satisfy / do not satisfy <em>pred</em> when it is invoked on the key and value of the association.</p> <blockquote><pre>(dict-filter (lambda (k v) (= k 1)) aed dict) => ((1 . 2)) (dict-remove (lambda (k) (= k 1)) aed dict) => ((3 . 4) (5 . 6))</pre></blockquote> -<p><code>(dict-alter</code> <em>dtd dict key failure success</em><code>)</code><br> -<code>(dict-alter!</code> <em>dtd dict key failure success</em><code>)</code></p> +<p><code>(dict-find-update</code> <em>dto dict key failure success</em><code>)</code><br> +<code>(dict-find-update!</code> <em>dto dict key failure success</em><code>)</code></p> <p>This procedure is a workhorse for dictionary lookup, insert, and delete. The dictionary <em>dict</em> is searched for an association whose key is the same as <em>key</em>. If one is not found, then the <em>failure</em> procedure is tail-called with two procedure arguments, <em>insert</em> and <em>ignore</em>.</p> -<p>If such an association is found, then the <em>success</em> procedure is tail-called with the matching key of <em>dict</em>, the associated value, and two procedure arguments, <em>update</em> and <em>remove</em>.</p> +<p>If such an association is found, then the <em>success</em> procedure is tail-called with the matching key of <em>dict</em>, the associated value, and two procedure arguments, <em>update</em> and <em>delete</em>.</p> <p>In either case, the values returned by <em>failure</em> or <em>success</em> are returned.</p> <ul> <li><p>Invoking <code>(</code><em>insert value</em><code>)</code> returns a dictionary that contains all the associations of <em>dict</em>, and in addition a new association that maps <em>key</em> to <em>value</em>.</p></li> <li><p>Invoking <code>(</code><em>ignore</em><code>)</code> has no effects and returns <em>dict</em> unchanged.</p></li> -<li><p>Invoking <code>(</code><em>update new-key new-value</em><code>)</code> returns a dictionary that contains all the associations of <em>dict</em>, except for the association whose key is the same as <em>key</em>, which is replaced or hidden by a new association that maps <em>new-key</em> to <em>new-value</em>. It is an error if <em>key</em> and <em>new-key</em> are not the same in the sense of the dictionary’s equality predicate.</p></li> -<li><p>Invoking <code>(</code><em>remove</em><code>)</code> returns a dictionary that contains all the associations of <em>dict</em>, except for the association with key key.</p></li> +<li><p>Invoking <code>(</code><em>update new-key new-value</em><code>)</code> returns a dictionary that contains all the associations of <em>dict</em>, except for the association whose key is the same as <em>key</em>, which is replaced or hidden by a new association that maps <em>new-key</em> to <em>new-value</em>. It is an error if <em>key</em> and <em>new-key</em> are not the same in the sense of the dictionary’s equality predicate.</p></li> +<li><p>Invoking <code>(</code><em>delete</em><code>)</code> returns a dictionary that contains all the associations of <em>dict</em>, except for the association with +key <em>key</em>. </ul> -<p>Here are four examples of <code>dict-alter</code>, +<p>Here are four examples of <code>dict-find-update</code>, one for each of the four procedures: <blockquote><pre> ;; ignore (define-values (dict value) - (dict-alter (alist->dict '((a . b))) 'c + (dict-find-update (alist->dict '((a . b))) 'c (lambda (insert ignore) (ignore)) (lambda args @@ -215,7 +214,7 @@ one for each of the four procedures: ;; insert (define-values (dict value) - (dict-alter (alist->dict '((a . b))) 'c + (dict-find-update (alist->dict '((a . b))) 'c (lambda (insert ignore) (insert 'd)) (lambda args @@ -226,7 +225,7 @@ one for each of the four procedures: ;; update (define-values (dict value) - (dict-alter (alist->dict '((a . b))) 'a + (dict-find-update (alist->dict '((a . b))) 'a (lambda args (error)) (lambda (key value update delete) @@ -236,7 +235,7 @@ one for each of the four procedures: ;; delete (define-values (dict value) - (dict-alter (alist->dict '((a . b) (c . d))) 'a + (dict-find-update (alist->dict '((a . b) (c . d))) 'a (lambda args (error)) (lambda (key value update delete) @@ -244,37 +243,37 @@ one for each of the four procedures: (dict->alist aed dict)) => ((c . d)) </pre></blockquote> <h3 id="the-whole-dictionary">The whole dictionary</h3> -<p><code>(dict-size</code> <em>dtd dict</em><code>)</code></p> +<p><code>(dict-size</code> <em>dto dict</em><code>)</code></p> <p>Returns an exact integer representing the number of associations in <em>dict</em>.</p> <blockquote><pre>(dict-size aed dict) => 3</pre></blockquote> -<p><code>(dict-count</code> <em>dtd pred dict</em><code>)</code></p> +<p><code>(dict-count</code> <em>dto pred dict</em><code>)</code></p> <p>Passes each association of dictionary as two arguments to <em>pred</em> and returns the number of times that <em>pred</em> returned true as an an exact integer.</p> <blockquote><pre>(dict-count aed dict (lambda (k v) (even? k))) => 0</pre></blockquote> -<p><code>(dict-any</code> <em>dtd pred dict</em><code>)</code></p> -<p>Passes each association of <em>dict</em> as two arguments to <em>pred</em> and returns the value of the first call to <em>pred</em> that returns true, after which no further calls are made. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. If all calls return false, <code>dict-any</code> returns false.</p> +<p><code>(dict-any</code> <em>dto pred dict</em><code>)</code></p> +<p>Passes each association of <em>dict</em> as two arguments to <em>pred</em> and returns the value of the first call to <em>pred</em> that returns true, after which no further calls are made. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. If all calls return false, <code>dict-any</code> returns false.</p> <blockquote><pre>(define (both-even? k v) (and (even? k) (even? v))) (dict-any aed both-even? '((2 . 4) (3 . 5))) => #t (dict-any aed both-even? '((1 . 2) (3 . 4))) => #f</pre></blockquote> -<p><code>(dict-every</code> <em>dtd pred dict</em><code>)</code></p> -<p>Passes each association of <em>dict</em> as two arguments to <em>pred</em> and returns <code>#f</code> after the first call to <em>pred</em> that returns false, after which no further calls are made. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. If all calls return true, <code>dict-any</code> returns the value of the last call, or <code>#t</code> if no calls are made.</p> +<p><code>(dict-every</code> <em>dto pred dict</em><code>)</code></p> +<p>Passes each association of <em>dict</em> as two arguments to <em>pred</em> and returns <code>#f</code> after the first call to <em>pred</em> that returns false, after which no further calls are made. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. If all calls return true, <code>dict-any</code> returns the value of the last call, or <code>#t</code> if no calls are made.</p> <blockquote><pre>(define (some-even? k v) (or (even? k) (even? v))) (dict-every aed some-even? '((2 . 3) (3 . 4))) => #t (dict-every aed some-even? '((1 . 3) (3 . 4))) => #f</pre></blockquote> -<p><code>(dict-keys</code> <em>dtd dict</em><code>)</code></p> -<p>Returns a list of the keys of <em>dict</em>. If the dictionary type is inherently ordered, associations appear in the inherent order; otherwise in an arbitrary order. The order may change when new elements are added to <em>dict</em>.</p> +<p><code>(dict-keys</code> <em>dto dict</em><code>)</code></p> +<p>Returns a list of the keys of <em>dict</em>. If the dictionary type is inherently ordered, associations appear in that order; otherwise in an arbitrary order. The order may change when new elements are added to <em>dict</em>.</p> <blockquote><pre>(dict-keys aed dict) => (1 3 5)</pre></blockquote> -<p><code>(dict-values</code> <em>dtd dict</em><code>)</code></p> +<p><code>(dict-values</code> <em>dto dict</em><code>)</code></p> <p>Returns a list of the values of <em>dict</em>. The results returned by <code>dict-keys</code> and <code>dict-values</code> are not necessarily ordered consistently.</p> <blockquote><pre>(dict-values aed dict) => (2 4 6)</pre></blockquote> -<p><code>(dict-entries</code> <em>dtd dict</em><code>)</code></p> +<p><code>(dict-entries</code> <em>dto dict</em><code>)</code></p> <p>Returns two values, the results of calling <code>dict-keys</code> and the result of calling <code>dict-values</code> on <em>dict</em>.</p> <blockquote><pre>(dict-entries aed dict) => ; 2 values (1 3 5) (2 4 6)</pre></blockquote> -<p><code>(dict-fold</code> <em>dtd proc knil dict</em><code>)</code></p> +<p><code>(dict-fold</code> <em>dto proc knil dict</em><code>)</code></p> <p>Invokes <em>proc</em> on each association of <em>dict</em> with three arguments: the key of the association, the value of the association, and an accumulated result of the previous invocation. For the first invocation, <em>knil</em> is used as the third argument. Returns the result of the last invocation, or <em>knil</em> if there was no invocation. Note that there is no guarantee of a consistent result if the dictionary does not have an inherent order.</p> <blockquote><pre>(dict-fold + 0 '((1 . 2) (3 . 4))) => 10</pre></blockquote> -<p><code>(dict-map->list</code> <em>dtd proc dict</em><code>)</code></p> +<p><code>(dict-map->list</code> <em>dto proc dict</em><code>)</code></p> <p>Returns a list of values that result from invoking <em>proc</em> on the keys and corresponding values of <em>dict</em>.</p> <blockquote><pre> (dict-map->list (lambda (k v) v) dict) => @@ -282,51 +281,51 @@ one for each of the four procedures: (dict-map->list - aed dict) => (-1 -1 -1) ; subtract value from key </pre></blockquote> -<p><code>(dict->alist</code> <em>dtd dict</em><code>)</code></p> +<p><code>(dict->alist</code> <em>dto dict</em><code>)</code></p> <p>Returns an alist whose keys and values are the keys and values of <em>dict</em>.</p> <p>Add <code>dict-map</code>, <code>dict-filter</code>, <code>dict-remove</code>, -and <code>dict-alter</code>. +and <code>dict-find-update</code>. </p> -<p><code>(dict-comparator</code> <em>dtd dict</em><code>)</code></p> +<p><code>(dict-comparator</code> <em>dto dict</em><code>)</code></p> <p>Return a comparator representing the type predicate, equality predicate, ordering predicate, and hash function of <em>dict</em>. The last two may be <code>#f</code> if the dictionary does not make use of these functions.</p> <p>If no comparator is relevant to the dictionary type, returns <code>#f</code>.</p> <h3 id="iteration">Iteration</h3> -<p><code>(dict-for-each</code> <em>dtd proc dict</em><code>)</code></p> -<p>Invokes <em>proc</em> on each key of <em>dict</em> and its corresponding value in that order. This procedure is used for doing operations on the whole dictionary. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. Returns an unspecified value.</p> +<p><code>(dict-for-each</code> <em>dto proc dict</em><code>)</code></p> +<p>Invokes <em>proc</em> on each key of <em>dict</em> and its corresponding value in that order. This procedure is used for doing operations on the whole dictionary. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. Returns an unspecified value.</p> <blockquote><pre>(define (write-key key value) (write key)) (dict-for-each write-key aed dict) => unspecified ; writes "135" to current output</pre></blockquote> -<p><code>(dict-for-each<</code> <em>dtd proc dict key</em><code>)</code><br> -<code>(dict-for-each<=</code> <em>dtd proc dict key</em><code>)</code><br> -<code>(dict-for-each></code> <em>dtd proc dict key</em><code>)</code><br> -<code>(dict-for-each>=</code> <em>dtd proc dict key</em><code>)</code></p> -<p>Invokes <em>proc</em> on each key of <em>dict</em> that is less than / less than or equal to / greater than / greater than or equal to <em>key</em> and its corresponding value. This procedure is used for doing operations on part of the dictionary. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. Returns an unspecified value.</p> -<p><code>(dict-for-each-in-open-interval</code> <em>dtd proc dict key1 key2</em><code>)</code><br> -<code>(dict-for-each-in-closed-interval</code> <em>dtd proc dict key1 key2</em><code>)</code><br> -<code>(dict-for-each-in-open-closed-interval</code> <em>dtd proc dict key1 key2</em><code>)</code><br> -<code>(dict-for-each-in-closed-open-interval</code> <em>dtd proc dict key1 key2</em><code>)</code></p> -<p>Invokes <em>proc</em> on each key of <em>dict</em> that is that is within the specified interval between <em>key1</em> and <em>key2</em>, and its corresponding value. This procedure is used for doing operations on part of the dictionary. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. Returns an unspecified value.</p> +<p><code>(dict-for-each<</code> <em>dto proc dict key</em><code>)</code><br> +<code>(dict-for-each<=</code> <em>dto proc dict key</em><code>)</code><br> +<code>(dict-for-each></code> <em>dto proc dict key</em><code>)</code><br> +<code>(dict-for-each>=</code> <em>dto proc dict key</em><code>)</code></p> +<p>Invokes <em>proc</em> on each key of <em>dict</em> that is less than / less than or equal to / greater than / greater than or equal to <em>key</em> and its corresponding value. This procedure is used for doing operations on part of the dictionary. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. Returns an unspecified value.</p> +<p><code>(dict-for-each-in-open-interval</code> <em>dto proc dict key1 key2</em><code>)</code><br> +<code>(dict-for-each-in-closed-interval</code> <em>dto proc dict key1 key2</em><code>)</code><br> +<code>(dict-for-each-in-open-closed-interval</code> <em>dto proc dict key1 key2</em><code>)</code><br> +<code>(dict-for-each-in-closed-open-interval</code> <em>dto proc dict key1 key2</em><code>)</code></p> +<p>Invokes <em>proc</em> on each key of <em>dict</em> that is that is within the specified interval between <em>key1</em> and <em>key2</em>, and its corresponding value. This procedure is used for doing operations on part of the dictionary. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. Returns an unspecified value.</p> <h3 id="generator-procedures">Generator procedures</h3> -<p><code>(make-dict-generator</code> <em>dtd dict</em><code>)</code></p> -<p>Returns a <a href="https://srfi.schemers.org/srfi-158/srfi-158.html">generator</a> that when invoked returns the associations of <em>dict</em> as pairs. When no associations are left, returns an end-of-file object. If the dictionary type is inherently ordered, associations are processed in the inherent order; otherwise in an arbitrary order. It is an error to mutate <em>dict</em> until the generator is exhausted.</p> -<p><code>(dict-set-accumulator</code> <em>dtd dict</em><code>)</code></p> +<p><code>(make-dict-generator</code> <em>dto dict</em><code>)</code></p> +<p>Returns a <a href="https://srfi.schemers.org/srfi-158/srfi-158.html">generator</a> that when invoked returns the associations of <em>dict</em> as pairs. When no associations are left, returns an end-of-file object. If the dictionary type is inherently ordered, associations are processed in that order; otherwise in an arbitrary order. It is an error to mutate <em>dict</em> until the generator is exhausted.</p> +<p><code>(dict-set-accumulator</code> <em>dto dict</em><code>)</code></p> <p>Returns a SRFI 158 accumulator procedure that when invoked on a pair adds the <code>car</code> and <code>cdr</code> of the pair as a key and value, returning the new value of the dictionary. If invoked on an end-of-file object, no action is taken and <em>dict</em> is returned. If a key to be added already exists in dictionary, the new value prevails.</p> -<p><code>(dict-adjoin-accumulator</code> <em>dtd dict</em><code>)</code></p> +<p><code>(dict-adjoin-accumulator</code> <em>dto dict</em><code>)</code></p> <p>The same as <code>dict-set-accumulator</code>, except that if a key to be added already exists in dictionary, the old value prevails.</p> -<h3 id="dictionary-type-descriptor-procedures">Dictionary type descriptor procedures</h3> -<p><code>(dtd?</code> <em>obj</em><code>)</code></p> -<p>Returns <code>#t</code> if <em>obj</em> is a DTD, and <code>#f</code> otherwise.</p> -<p><code>(make-dtd</code> <em>arg</em> …<code>)</code><br> -<code>(dtd (</code><em>proc-id procname</em><code>)</code> …<code>)</code> [syntax]</p> -<p>Returns a new DTD providing procedures that allow manipulation of dictionaries of that type. The <em>args</em> are alternately <em>proc-ids</em> and corresponding <em>procs</em>.</p> +<h3 id="dictionary-type-object-procedures">Dictionary type object procedures</h3> +<p><code>(dto?</code> <em>obj</em><code>)</code></p> +<p>Returns <code>#t</code> if <em>obj</em> is a DTO, and <code>#f</code> otherwise.</p> +<p><code>(make-dto</code> <em>arg</em> …<code>)</code><br> +<code>(dto (</code><em>proc-id procname</em><code>)</code> …<code>)</code> [syntax]</p> +<p>Returns a new DTO providing procedures that allow manipulation of dictionaries of that type. The <em>args</em> are find-updatenately <em>proc-ids</em> and corresponding <em>procs</em>.</p> <p>A <em>proc-id</em> argument is the value of a variable whose name is the same as a procedure (except those in this section and the Exceptions section) suffixed with <code>-id</code>, and a <em>proc</em> argument is the specific procedure implementing it for this type. Note that there is only one proc-id variable for each pair of pure and impure procedures: the proc-id variable for <code>dict-map-id</code> and <code>dict-map!</code> is <code>dict-map-id</code>.</p> -<p>The following proc-id variables (and corresponding primitive procedures) need to be provided in order for the DTD to support the full set of dictionary procedures:</p> +<p>The following proc-id variables (and corresponding primitive procedures) need to be provided in order for the DTO to support the full set of dictionary procedures:</p> <ul> <li><code>dictionary?-id</code></li> -<li><code>dict-alter-id</code></li> +<li><code>dict-find-update-id</code></li> <li><code>dict-comparator-id</code></li> <li><code>dict-map-id</code></li> <li><code>dict-pure?-id</code></li> @@ -334,7 +333,7 @@ the proc-id variable for <code>dict-map-id</code> and <code>dict-map!</code> is <li><code>dict-size-id</code></li> </ul> <p>Note that it is not an error to omit any of these, but some dictionary procedures may be unavailable.</p> -<p>There are additional proc-id variables that may be provided with corresponding procedures in order to increase efficiency. For example, it is not necessary to provide a <code>dict-ref</code> procedure, because the default version is built on top of <code>dict-alter</code> or <code>dict-alter!</code>. But if the underlying dictionary provides its own <code>-ref</code> procedure, it may be more efficient to specify it to <code>make-dtd</code> using <code>dict-ref-id</code>. Here is the list of additional proc-id variables:</p> +<p>There are additional proc-id variables that may be provided with corresponding procedures in order to increase efficiency. For example, it is not necessary to provide a <code>dict-ref</code> procedure, because the default version is built on top of <code>dict-find-update</code> or <code>dict-find-update!</code>. But if the underlying dictionary provides its own <code>-ref</code> procedure, it may be more efficient to specify it to <code>make-dto</code> using <code>dict-ref-id</code>. Here is the list of additional proc-id variables:</p> <ul> <li><code>dict->alist-id</code></li> <li><code>dict-adjoin-accumulator-id</code></li> @@ -375,18 +374,18 @@ the proc-id variable for <code>dict-map-id</code> and <code>dict-map!</code> is <li><code>dict=?-id</code></li> <li><code>make-dict-generator-id</code></li> </ul> -<p>The <code>dtd</code> macro behaves like a wrapper around <code>make-dtd</code> with parentheses around each <em>procid-procname</em> pair. The macro may also verify that the <em>proc-ids</em> are valid, that there are no duplicates, etc.</p> -<p><code>(make-alist-dtd</code> <em>equal</em><code>)</code></p> -<p>Returns a DTD for manipulating an alist using the equality predicate <em>equal</em>.</p> -<blockquote><code>(make-alist-dtd =) => a DTD for alists using numeric equality</code></blockquote> -<p><code>(dtd-ref</code> <em>dtd proc-id</em><code>)</code></p> -<p>Returns the procedure designated by <em>proc-id</em> from <em>dtd</em>. -This allows the ability to call a particular DTD procedure multiple times more efficiently.</p> +<p>The <code>dto</code> macro behaves like a wrapper around <code>make-dto</code> with parentheses around each <em>procid-procname</em> pair. The macro may also verify that the <em>proc-ids</em> are valid, that there are no duplicates, etc.</p> +<p><code>(make-alist-dto</code> <em>equal</em><code>)</code></p> +<p>Returns a DTO for manipulating an alist using the equality predicate <em>equal</em>.</p> +<blockquote><code>(make-alist-dto =) => a DTO for alists using numeric equality</code></blockquote> +<p><code>(dto-ref</code> <em>dto proc-id</em><code>)</code></p> +<p>Returns the procedure designated by <em>proc-id</em> from <em>dto</em>. +This allows the ability to call a particular DTO procedure multiple times more efficiently.</p> <h3 id="exceptions">Exceptions</h3> <p><code>(dictionary-error</code> <em>message irritant</em> ... <code>)</code></p> <p>Returns a dictionary error with the given <em>message</em> (a string) and <em>irritants</em> (any objects). -If a particular procedure in a DTD cannot be implemented, it instead +If a particular procedure in a DTO cannot be implemented, it instead should signal an appropriate dictionary error that can be reliably caught. <p><code>(dictionary-error?</code> <em>obj</em><code>)</code></p> <p>Returns <code>#t</code> if <em>obj</em> is a dictionary error @@ -395,12 +394,12 @@ and <code>#f</code> otherwise. <p>Returns the message associated with <em>dictionary-error.</em></p> <p><code>(dictionary-irritants</code> <em>dictionary-error</em><code>)</code></p> <p>Returns a list of the irritants associated with <em>dictionary-error</em>.</p> -<h3 id="exported-dtds">Exported DTDs</h3> -<p>The following DTDs are exported from this SRFI: -<code>srfi-69-dtd</code>, <code>hash-table-dtd</code>, <code>srfi-126-dtd</code>, -<code>mapping-dtd</code>, <code>hash-mapping-dtd</code>, -<code>alist-eqv-dtd</code>, and <code>alist-equal-dtd</code>. -The last two provide DTDs for alists using <code>eqv?</code> +<h3 id="exported-dtos">Exported DTOs</h3> +<p>The following DTOs are exported from this SRFI: +<code>srfi-69-dto</code>, <code>hash-table-dto</code>, <code>srfi-126-dto</code>, +<code>mapping-dto</code>, <code>hash-mapping-dto</code>, +<code>alist-eqv-dto</code>, and <code>alist-equal-dto</code>. +The last two provide DTOs for alists using <code>eqv?</code> and <code>equal?</code> respectively.</p> <h2 id="implementation">Implementation</h2> @@ -422,31 +421,31 @@ new dictionary types that may not have complete dictionary APIs:</p> <dt>dict-ref</dt> <dd>dict-pure?</dd> - <dd>dict-alter or dict-alter!</dd> + <dd>dict-find-update or dict-find-update!</dd> <dt>dict-ref/default</dt> <dd>dict-ref</dd> <dt>dict-set</dt> - <dd>dict-alter</dd> + <dd>dict-find-update</dd> <dt>dict-adjoin</dt> - <dd>dict-alter</dd> + <dd>dict-find-update</dd> <dt>dict-delete</dt> <dd>dict-delete-all</dd> <dt>dict-delete-all</dt> - <dd>dict-alter</dd> + <dd>dict-find-update</dd> <dt>dict-replace</dt> - <dd>dict-alter</dd> + <dd>dict-find-update</dd> <dt>dict-intern</dt> - <dd>dict-alter</dd> + <dd>dict-find-update</dd> <dt>dict-update</dt> - <dd>dict-alter</dd> + <dd>dict-find-update</dd> <dt>dict-update/default</dt> <dd>dict-update</dd> diff --git a/srfi/225.sld b/srfi/225.sld index 1d34430..94699e7 100644 --- a/srfi/225.sld +++ b/srfi/225.sld @@ -49,8 +49,8 @@ dict-filter! dict-remove dict-remove! - dict-alter - dict-alter! + dict-find-update + dict-find-update! ;; whole dictionary dict-size @@ -82,11 +82,11 @@ dict-adjoin-accumulator ;; dictionary type descriptors - dtd? - make-dtd - dtd - make-alist-dtd - dtd-ref + dto? + make-dto + dto + make-alist-dto + dto-ref ;; exceptions dictionary-error @@ -114,7 +114,7 @@ dict-map-id dict-filter-id dict-remove-id - dict-alter-id + dict-find-update-id dict-size-id dict-count-id dict-any-id @@ -139,9 +139,9 @@ dict-set-accumulator-id dict-adjoin-accumulator-id - ;; basic DTDs - alist-eqv-dtd - alist-equal-dtd) + ;; basic DTOs + alist-eqv-dto + alist-equal-dto) ;; implementations (include "indexes.scm") @@ -149,34 +149,34 @@ (include "default-impl.scm") (include "alist-impl.scm") - ;; library-dependent DTD exports + ;; library-dependent DTO exports ;; and implementations ;; - ;;srfi-69-dtd - ;;hash-table-dtd - ;;srfi-126-dtd - ;;mapping-dtd - ;;hash-mapping-dtd + ;;srfi-69-dto + ;;hash-table-dto + ;;srfi-126-dto + ;;mapping-dto + ;;hash-mapping-dto (cond-expand ((library (srfi 69)) (import (prefix (srfi 69) t69-)) (include "srfi-69-impl.scm") - (export srfi-69-dtd)) + (export srfi-69-dto)) (else)) (cond-expand ((library (srfi 125)) (import (prefix (srfi 125) t125-)) (include "srfi-125-impl.scm") - (export hash-table-dtd)) + (export hash-table-dto)) (else)) (cond-expand ((library (srfi 126)) (import (prefix (srfi 126) t126-)) (include "srfi-126-impl.scm") - (export srfi-126-dtd)) + (export srfi-126-dto)) (else)) (cond-expand @@ -186,6 +186,6 @@ (srfi 146 hash)) (include "srfi-146-impl.scm" "srfi-146-hash-impl.scm") - (export mapping-dtd - hash-mapping-dtd)) + (export mapping-dto + hash-mapping-dto)) (else))) diff --git a/srfi/alist-impl.scm b/srfi/alist-impl.scm index e2b2a29..19d42b6 100644 --- a/srfi/alist-impl.scm +++ b/srfi/alist-impl.scm @@ -1,14 +1,14 @@ -(define (make-alist-dtd key=) +(define (make-alist-dto key=) - (define (alist? dtd l) + (define (alist? dto l) (and (list? l) (or (null? l) (pair? (car l))))) - (define (alist-mutable? dtd alist) + (define (alist-mutable? dto alist) #f) - (define (alist-map dtd proc alist) + (define (alist-map dto proc alist) (map (lambda (e) (define key (car e)) @@ -16,19 +16,19 @@ (cons key (proc key value))) alist)) - (define (alist-filter dtd pred alist) + (define (alist-filter dto pred alist) (filter (lambda (e) (pred (car e) (cdr e))) alist)) - (define (alist-delete dtd key alist) + (define (alist-delete dto key alist) (filter (lambda (entry) (not (key= (car entry) key))) alist)) - (define (alist-alter dtd alist key failure success) + (define (alist-find-update dto alist key failure success) (define (handle-success pair) (define old-key (car pair)) (define old-value (cdr pair)) @@ -43,10 +43,10 @@ (let ((new-list (alist-cons new-key new-value - (alist-delete dtd old-key alist)))) + (alist-delete dto old-key alist)))) new-list)))) (define (remove) - (alist-delete dtd old-key alist)) + (alist-delete dto old-key alist)) (success old-key old-value update remove)) (define (handle-failure) @@ -59,30 +59,30 @@ ((assoc key alist key=) => handle-success) (else (handle-failure)))) - (define (alist-size dtd alist) + (define (alist-size dto alist) (length alist)) - (define (alist-foreach dtd proc alist) + (define (alist-foreach dto proc alist) (define (proc* e) (proc (car e) (cdr e))) (for-each proc* alist)) - (define (alist->alist dtd alist) + (define (alist->alist dto alist) alist) - (define (alist-comparator dtd dictionary) + (define (alist-comparator dto dictionary) #f) - (make-dtd + (make-dto dictionary?-id alist? dict-mutable?-id alist-mutable? dict-map-id alist-map dict-filter-id alist-filter - dict-alter-id alist-alter + dict-find-update-id alist-find-update dict-size-id alist-size dict-for-each-id alist-foreach dict->alist-id alist->alist dict-comparator-id alist-comparator)) -(define alist-eqv-dtd (make-alist-dtd eqv?)) -(define alist-equal-dtd (make-alist-dtd equal?)) +(define alist-eqv-dto (make-alist-dto eqv?)) +(define alist-equal-dto (make-alist-dto equal?)) diff --git a/srfi/default-impl.scm b/srfi/default-impl.scm index a0c9584..dea21ee 100644 --- a/srfi/default-impl.scm +++ b/srfi/default-impl.scm @@ -1,81 +1,81 @@ -(define default-dtd +(define default-dto (let () - ;; implementation of "default" dtd, used as a filler for undefined - ;; functions in other dtds + ;; implementation of "default" dto, used as a filler for undefined + ;; functions in other dtos ;; primitives (define (not-implemented name) - (lambda (dtd . args) - (raise (dictionary-error (string-append name " not implemented") dtd)))) + (lambda (dto . args) + (raise (dictionary-error (string-append name " not implemented") dto)))) (define default-dictionary? (not-implemented "dictionary?")) (define default-dict-mutable? (not-implemented "dict-mutable?")) (define default-dict-size (not-implemented "dict-size")) - (define default-dict-alter (not-implemented "dict-alter")) + (define default-dict-find-update (not-implemented "dict-find-update")) - (define (dict-alter* dtd dict key fail success) - (if (dict-mutable? dtd dict) - (dict-alter! dtd dict key fail success) - (dict-alter dtd dict key fail success))) + (define (dict-find-update* dto dict key fail success) + (if (dict-mutable? dto dict) + (dict-find-update! dto dict key fail success) + (dict-find-update dto dict key fail success))) - (define (dict-delete-all* dtd dict keys) - (if (dict-mutable? dtd dict) - (dict-delete-all! dtd dict keys) - (dict-delete-all dtd dict keys))) + (define (dict-delete-all* dto dict keys) + (if (dict-mutable? dto dict) + (dict-delete-all! dto dict keys) + (dict-delete-all dto dict keys))) - (define (dict-update* dtd dict key updater fail success) - (if (dict-mutable? dtd dict) - (dict-update! dtd dict key updater fail success) - (dict-update dtd dict key updater fail success))) + (define (dict-update* dto dict key updater fail success) + (if (dict-mutable? dto dict) + (dict-update! dto dict key updater fail success) + (dict-update dto dict key updater fail success))) - (define (dict-filter* dtd pred dictionary) - (if (dict-mutable? dtd dictionary) - (dict-filter! dtd pred dictionary) - (dict-filter dtd pred dictionary))) + (define (dict-filter* dto pred dictionary) + (if (dict-mutable? dto dictionary) + (dict-filter! dto pred dictionary) + (dict-filter dto pred dictionary))) - (define (dict-replace* dtd dict key val) - (if (dict-mutable? dtd dict) - (dict-replace! dtd dict key val) - (dict-replace dtd dict key val))) + (define (dict-replace* dto dict key val) + (if (dict-mutable? dto dict) + (dict-replace! dto dict key val) + (dict-replace dto dict key val))) - (define (default-dict-empty? dtd dictionary) - (= 0 (dict-size dtd dictionary))) + (define (default-dict-empty? dto dictionary) + (= 0 (dict-size dto dictionary))) - (define (default-dict=? dtd = dict1 dict2) + (define (default-dict=? dto = dict1 dict2) (define (check-entries* keys) (cond ((null? keys) #t) (else (let* ((key (car keys)) - (d1-value (dict-ref dtd dict1 key))) - (dict-ref dtd dict2 key + (d1-value (dict-ref dto dict1 key))) + (dict-ref dto dict2 key (lambda () #f) (lambda (d2-value) (if (= d1-value d2-value) (check-entries* (cdr keys)) #f))))))) - (and (= (dict-size dtd dict1) - (dict-size dtd dict2)) - (check-entries* (dict-keys dtd dict1)))) + (and (= (dict-size dto dict1) + (dict-size dto dict2)) + (check-entries* (dict-keys dto dict1)))) - (define (default-dict-contains? dtd dictionary key) - (dict-ref dtd dictionary key + (define (default-dict-contains? dto dictionary key) + (dict-ref dto dictionary key (lambda () #f) (lambda (x) #t))) - (define (default-dict-ref dtd dictionary key failure success) - (dict-alter* dtd dictionary key + (define (default-dict-ref dto dictionary key failure success) + (dict-find-update* dto dictionary key (lambda (insert ignore) (failure)) (lambda (key value update remove) (success value)))) - (define (default-dict-ref/default dtd dictionary key default) - (dict-ref dtd dictionary key + (define (default-dict-ref/default dto dictionary key default) + (dict-ref dto dictionary key (lambda () default) (lambda (x) x))) ;; private - (define (default-dict-set* dtd dictionary use-old? objs) + (define (default-dict-set* dto dictionary use-old? objs) (let loop ((objs objs) (dictionary dictionary)) (cond @@ -85,7 +85,7 @@ (error "mismatch of key / values argument list" objs)) (else (let* ((key (car objs)) (value (cadr objs)) - (new-d (dict-alter* dtd dictionary key + (new-d (dict-find-update* dto dictionary key (lambda (insert ignore) (insert value)) (lambda (key old-value update delete) @@ -93,22 +93,22 @@ (loop (cddr objs) new-d)))))) - (define (default-dict-set dtd dictionary . objs) - (default-dict-set* dtd dictionary #f objs)) + (define (default-dict-set dto dictionary . objs) + (default-dict-set* dto dictionary #f objs)) - (define (default-dict-adjoin dtd dictionary . objs) - (default-dict-set* dtd dictionary #t objs)) + (define (default-dict-adjoin dto dictionary . objs) + (default-dict-set* dto dictionary #t objs)) - (define (default-dict-delete dtd dictionary . keys) - (dict-delete-all* dtd dictionary keys)) + (define (default-dict-delete dto dictionary . keys) + (dict-delete-all* dto dictionary keys)) - (define (default-dict-delete-all dtd dictionary keylist) + (define (default-dict-delete-all dto dictionary keylist) (let loop ((keylist keylist) (d dictionary)) (cond ((null? keylist) d) (else (let* ((key (car keylist)) - (new-d (dict-alter* dtd d key + (new-d (dict-find-update* dto d key (lambda (_ ignore) (ignore)) (lambda (key old-value _ delete) @@ -116,75 +116,75 @@ (loop (cdr keylist) new-d)))))) - (define (default-dict-replace dtd dictionary key value) - (dict-alter* dtd dictionary key + (define (default-dict-replace dto dictionary key value) + (dict-find-update* dto dictionary key (lambda (_ ignore) (ignore)) (lambda (key old-value update _) (update key value)))) - (define (default-dict-intern dtd dictionary key failure) - (dict-alter* dtd dictionary key + (define (default-dict-intern dto dictionary key failure) + (dict-find-update* dto dictionary key (lambda (insert _) (let ((value (failure))) (values (insert value) value))) (lambda (key value update _) (values dictionary value)))) - (define (default-dict-update dtd dictionary key updater failure success) - (dict-alter* dtd dictionary key + (define (default-dict-update dto dictionary key updater failure success) + (dict-find-update* dto dictionary key (lambda (insert ignore) (insert (updater (failure)))) (lambda (key value update _) (update key (updater (success value)))))) - (define (default-dict-update/default dtd dictionary key updater default) - (dict-update* dtd dictionary key updater + (define (default-dict-update/default dto dictionary key updater default) + (dict-update* dto dictionary key updater (lambda () default) (lambda (x) x))) - (define (default-dict-pop dtd dictionary) + (define (default-dict-pop dto dictionary) (define (do-pop) (call/cc (lambda (cont) - (dict-for-each dtd + (dict-for-each dto (lambda (key value) (define new-dict - (dict-delete-all* dtd dictionary (list key))) + (dict-delete-all* dto dictionary (list key))) (cont new-dict key value)) dictionary)))) - (define empty? (dict-empty? dtd dictionary)) + (define empty? (dict-empty? dto dictionary)) (if empty? (error "popped empty dictionary") (do-pop))) - (define (default-dict-map dtd mapper dictionary) - (define keys (dict-keys dtd dictionary)) + (define (default-dict-map dto mapper dictionary) + (define keys (dict-keys dto dictionary)) (let loop ((keys keys) (dict dictionary)) (if (null? keys) dict (let* ((key (car keys)) - (val (mapper key (dict-ref dtd dict key)))) + (val (mapper key (dict-ref dto dict key)))) (loop (cdr keys) - (dict-replace* dtd dict key val)))))) + (dict-replace* dto dict key val)))))) - (define (default-dict-filter dtd pred dictionary) - (define keys (dict-keys dtd dictionary)) + (define (default-dict-filter dto pred dictionary) + (define keys (dict-keys dto dictionary)) (define keys-to-delete (filter (lambda (key) - (not (pred key (dict-ref dtd dictionary key)))) + (not (pred key (dict-ref dto dictionary key)))) keys)) - (dict-delete-all* dtd dictionary keys-to-delete)) + (dict-delete-all* dto dictionary keys-to-delete)) - (define (default-dict-remove dtd pred dictionary) - (dict-filter* dtd (lambda (key value) + (define (default-dict-remove dto pred dictionary) + (dict-filter* dto (lambda (key value) (not (pred key value))) dictionary)) - (define (default-dict-count dtd pred dictionary) - (dict-fold dtd + (define (default-dict-count dto pred dictionary) + (dict-fold dto (lambda (key value acc) (if (pred key value) (+ 1 acc) @@ -192,10 +192,10 @@ 0 dictionary)) - (define (default-dict-any dtd pred dictionary) + (define (default-dict-any dto pred dictionary) (call/cc (lambda (cont) - (dict-for-each dtd + (dict-for-each dto (lambda (key value) (define ret (pred key value)) (when ret @@ -203,11 +203,11 @@ dictionary) #f))) - (define (default-dict-every dtd pred dictionary) + (define (default-dict-every dto pred dictionary) (define last #t) (call/cc (lambda (cont) - (dict-for-each dtd + (dict-for-each dto (lambda (key value) (define ret (pred key value)) (when (not ret) @@ -216,25 +216,25 @@ dictionary) last))) - (define (default-dict-keys dtd dictionary) + (define (default-dict-keys dto dictionary) (reverse - (dict-fold dtd + (dict-fold dto (lambda (key value acc) (cons key acc)) '() dictionary))) - (define (default-dict-values dtd dictionary) + (define (default-dict-values dto dictionary) (reverse - (dict-fold dtd + (dict-fold dto (lambda (key value acc) (cons value acc)) '() dictionary))) - (define (default-dict-entries dtd dictionary) + (define (default-dict-entries dto dictionary) (define pair - (dict-fold dtd + (dict-fold dto (lambda (key value acc) (cons (cons key (car acc)) (cons value (cdr acc)))) @@ -243,25 +243,25 @@ (values (reverse (car pair)) (reverse (cdr pair)))) - (define (default-dict-fold dtd proc knil dictionary) + (define (default-dict-fold dto proc knil dictionary) (define acc knil) - (dict-for-each dtd + (dict-for-each dto (lambda (key value) (set! acc (proc key value acc))) dictionary) acc) - (define (default-dict-map->list dtd proc dictionary) + (define (default-dict-map->list dto proc dictionary) (define reverse-lst - (dict-fold dtd + (dict-fold dto (lambda (key value lst) (cons (proc key value) lst)) '() dictionary)) (reverse reverse-lst)) - (define (default-dict->alist dtd dictionary) - (dict-map->list dtd + (define (default-dict->alist dto dictionary) + (dict-map->list dto cons dictionary)) @@ -269,66 +269,66 @@ (define default-dict-for-each (not-implemented "dict-for-each")) - (define (default-dict-for-each/filtered dtd pred proc dict) - (dict-for-each dtd + (define (default-dict-for-each/filtered dto pred proc dict) + (dict-for-each dto (lambda (key value) (when (pred key) (proc key value))) dict)) - (define (default-dict-for-each< dtd proc dict key) - (define cmp (dict-comparator dtd dict)) + (define (default-dict-for-each< dto proc dict key) + (define cmp (dict-comparator dto dict)) (define (pred k) (<? cmp k key)) - (default-dict-for-each/filtered dtd pred proc dict)) + (default-dict-for-each/filtered dto pred proc dict)) - (define (default-dict-for-each<= dtd proc dict key) - (define cmp (dict-comparator dtd dict)) + (define (default-dict-for-each<= dto proc dict key) + (define cmp (dict-comparator dto dict)) (define (pred k) (<=? cmp k key)) - (default-dict-for-each/filtered dtd pred proc dict)) + (default-dict-for-each/filtered dto pred proc dict)) - (define (default-dict-for-each> dtd proc dict key) - (define cmp (dict-comparator dtd dict)) + (define (default-dict-for-each> dto proc dict key) + (define cmp (dict-comparator dto dict)) (define (pred k) (>? cmp k key)) - (default-dict-for-each/filtered dtd pred proc dict)) + (default-dict-for-each/filtered dto pred proc dict)) - (define (default-dict-for-each>= dtd proc dict key) - (define cmp (dict-comparator dtd dict)) + (define (default-dict-for-each>= dto proc dict key) + (define cmp (dict-comparator dto dict)) (define (pred k) (>=? cmp k key)) - (default-dict-for-each/filtered dtd pred proc dict)) + (default-dict-for-each/filtered dto pred proc dict)) - (define (default-dict-for-each-in-open-interval dtd proc dict key1 key2) - (define cmp (dict-comparator dtd dict)) + (define (default-dict-for-each-in-open-interval dto proc dict key1 key2) + (define cmp (dict-comparator dto dict)) (define (pred k) (<? cmp key1 k key2)) - (default-dict-for-each/filtered dtd pred proc dict)) + (default-dict-for-each/filtered dto pred proc dict)) - (define (default-dict-for-each-in-closed-interval dtd proc dict key1 key2) - (define cmp (dict-comparator dtd dict)) + (define (default-dict-for-each-in-closed-interval dto proc dict key1 key2) + (define cmp (dict-comparator dto dict)) (define (pred k) (<=? cmp key1 k key2)) - (default-dict-for-each/filtered dtd pred proc dict)) + (default-dict-for-each/filtered dto pred proc dict)) - (define (default-dict-for-each-in-open-closed-interval dtd proc dict key1 key2) - (define cmp (dict-comparator dtd dict)) + (define (default-dict-for-each-in-open-closed-interval dto proc dict key1 key2) + (define cmp (dict-comparator dto dict)) (define (pred k) (and (<? cmp key1 k) (<=? cmp k key2))) - (default-dict-for-each/filtered dtd pred proc dict)) + (default-dict-for-each/filtered dto pred proc dict)) - (define (default-dict-for-each-in-closed-open-interval dtd proc dict key1 key2) - (define cmp (dict-comparator dtd dict)) + (define (default-dict-for-each-in-closed-open-interval dto proc dict key1 key2) + (define cmp (dict-comparator dto dict)) (define (pred k) (and (<=? cmp key1 k) (<? cmp k key2))) - (default-dict-for-each/filtered dtd pred proc dict)) + (default-dict-for-each/filtered dto pred proc dict)) - (define (default-make-dict-generator dtd dict) + (define (default-make-dict-generator dto dict) (define-values (keys vals) - (dict-entries dtd dict)) + (dict-entries dto dict)) (lambda () (if (null? keys) (eof-object) @@ -338,27 +338,27 @@ (set! vals (cdr vals)) (cons key value))))) - (define (default-dict-accumulator dtd dict acc-proc) + (define (default-dict-accumulator dto dict acc-proc) (lambda (arg) (if (eof-object? arg) dict - (set! dict (acc-proc dtd dict (car arg) (cdr arg)))))) + (set! dict (acc-proc dto dict (car arg) (cdr arg)))))) - (define (default-dict-set-accumulator dtd dict) - (if (dict-mutable? dtd dict) - (default-dict-accumulator dtd dict dict-set!) - (default-dict-accumulator dtd dict dict-set))) + (define (default-dict-set-accumulator dto dict) + (if (dict-mutable? dto dict) + (default-dict-accumulator dto dict dict-set!) + (default-dict-accumulator dto dict dict-set))) - (define (default-dict-adjoin-accumulator dtd dict) - (if (dict-mutable? dtd dict) - (default-dict-accumulator dtd dict dict-adjoin!) - (default-dict-accumulator dtd dict dict-adjoin))) + (define (default-dict-adjoin-accumulator dto dict) + (if (dict-mutable? dto dict) + (default-dict-accumulator dto dict dict-adjoin!) + (default-dict-accumulator dto dict dict-adjoin))) (let () - (define null-dtd (make-dtd-private (make-vector dict-procedures-count #f))) - (define default-dtd - (make-modified-dtd - null-dtd + (define null-dto (make-dto-private (make-vector dict-procedures-count #f))) + (define default-dto + (make-modified-dto + null-dto dictionary?-id default-dictionary? dict-empty?-id default-dict-empty? dict-contains?-id default-dict-contains? @@ -378,7 +378,7 @@ dict-map-id default-dict-map dict-filter-id default-dict-filter dict-remove-id default-dict-remove - dict-alter-id default-dict-alter + dict-find-update-id default-dict-find-update dict-size-id default-dict-size dict-count-id default-dict-count dict-any-id default-dict-any @@ -411,7 +411,7 @@ (lambda (proc index) (unless (and proc (procedure? proc)) (error "Missing or wrong default procedure definition" proc index))) - (procvec default-dtd) + (procvec default-dto) (list->vector (iota dict-procedures-count))) - default-dtd))) + default-dto))) diff --git a/srfi/externals.scm b/srfi/externals.scm index 519bccf..ce24b19 100644 --- a/srfi/externals.scm +++ b/srfi/externals.scm @@ -1,62 +1,62 @@ ;; procedure definitions that don't rely on concrete implementations -(define-record-type <dtd> - (make-dtd-private procvec) - dtd? +(define-record-type <dto> + (make-dto-private procvec) + dto? (procvec procvec)) -(define-record-type <dtd-err> +(define-record-type <dto-err> (make-dictionary-error message irritants) dictionary-error? (message dictionary-message) (irritants dictionary-irritants)) -;; shorthand access to dtd procedure by index -(define-syntax dtd-ref-stx +;; shorthand access to dto procedure by index +(define-syntax dto-ref-stx (syntax-rules () - ((_ dtd index) + ((_ dto index) (begin - (vector-ref (procvec dtd) index))))) + (vector-ref (procvec dto) index))))) ;; shorthand to define proc with using proc index (define-syntax define/dict-proc (syntax-rules () ((_ proc index) - (define (proc dtd . args) - (assume (dtd? dtd)) - (apply (dtd-ref-stx dtd index) dtd args))))) + (define (proc dto . args) + (assume (dto? dto)) + (apply (dto-ref-stx dto index) dto args))))) ;; define mutable and immutable versions of a procedure (such as dict-set! and dict-set) ;; with appropriate assertion for dict-mutable? value -;; when dtd is first arg, and dict is second arg +;; when dto is first arg, and dict is second arg (define-syntax define/dict-proc-pair (syntax-rules () ((_ proc-immutable proc-mutable index) (begin - (define (proc-mutable dtd dict . args) - (assume (dtd? dtd)) - (assume ((dtd-ref-stx dtd dict-mutable?-id) dtd dict) index) - (apply (dtd-ref-stx dtd index) dtd dict args)) - (define (proc-immutable dtd dict . args) - (assume (dtd? dtd)) - (assume (not ((dtd-ref-stx dtd dict-mutable?-id) dtd dict)) index) - (apply (dtd-ref-stx dtd index) dtd dict args)))))) + (define (proc-mutable dto dict . args) + (assume (dto? dto)) + (assume ((dto-ref-stx dto dict-mutable?-id) dto dict) index) + (apply (dto-ref-stx dto index) dto dict args)) + (define (proc-immutable dto dict . args) + (assume (dto? dto)) + (assume (not ((dto-ref-stx dto dict-mutable?-id) dto dict)) index) + (apply (dto-ref-stx dto index) dto dict args)))))) ;; define mutable and immutable versions of a procedure (such as dict-set! and dict-set) ;; with appropriate assertion for dict-mutable? value -;; when dtd is first arg, and dict is third arg (ie filter, map shape signature) +;; when dto is first arg, and dict is third arg (ie filter, map shape signature) (define-syntax define/dict-proc-pair* (syntax-rules () ((_ proc-immutable proc-mutable index) (begin - (define (proc-mutable dtd proc dict) - (assume (dtd? dtd)) - (assume ((dtd-ref-stx dtd dict-mutable?-id) dtd dict) index) - ((dtd-ref-stx dtd index) dtd proc dict)) - (define (proc-immutable dtd proc dict) - (assume (dtd? dtd)) - (assume (not ((dtd-ref-stx dtd dict-mutable?-id) dtd dict)) index) - ((dtd-ref-stx dtd index) dtd proc dict)))))) + (define (proc-mutable dto proc dict) + (assume (dto? dto)) + (assume ((dto-ref-stx dto dict-mutable?-id) dto dict) index) + ((dto-ref-stx dto index) dto proc dict)) + (define (proc-immutable dto proc dict) + (assume (dto? dto)) + (assume (not ((dto-ref-stx dto dict-mutable?-id) dto dict)) index) + ((dto-ref-stx dto index) dto proc dict)))))) (define/dict-proc dictionary? dictionary?-id) (define/dict-proc dict-empty? dict-empty?-id) @@ -66,17 +66,17 @@ (define dict-ref (case-lambda - ((dtd dict key) - (dict-ref dtd dict key + ((dto dict key) + (dict-ref dto dict key (lambda () (error "Key not found in dictionary" dict key)) values)) - ((dtd dict key failure) - (dict-ref dtd dict key failure values)) + ((dto dict key failure) + (dict-ref dto dict key failure values)) - ((dtd dict key failure success) - (assume (dtd? dtd)) - ((dtd-ref-stx dtd dict-ref-id) dtd dict key failure success)))) + ((dto dict key failure success) + (assume (dto? dto)) + ((dto-ref-stx dto dict-ref-id) dto dict key failure success)))) (define/dict-proc dict-ref/default dict-ref/default-id) (define/dict-proc-pair dict-set dict-set! dict-set-id) @@ -88,40 +88,40 @@ (define dict-update (case-lambda - ((dtd dict key updater) - (dict-update dtd dict key updater + ((dto dict key updater) + (dict-update dto dict key updater (lambda () (error "Key not found in dictionary" dict key)) values)) - ((dtd dict key updater failure) - (dict-update dtd dict key updater failure values)) + ((dto dict key updater failure) + (dict-update dto dict key updater failure values)) - ((dtd dict key updater failure success) - (assume (dtd? dtd)) - (assume (not ((dtd-ref-stx dtd dict-mutable?-id) dtd dict))) - ((dtd-ref-stx dtd dict-update-id) dtd dict key updater failure success)))) + ((dto dict key updater failure success) + (assume (dto? dto)) + (assume (not ((dto-ref-stx dto dict-mutable?-id) dto dict))) + ((dto-ref-stx dto dict-update-id) dto dict key updater failure success)))) (define dict-update! (case-lambda - ((dtd dict key updater) - (dict-update dtd dict key updater + ((dto dict key updater) + (dict-update dto dict key updater (lambda () (error "Key not found in dictionary" dict key)) values)) - ((dtd dict key updater failure) - (dict-update dtd dict key updater failure values)) + ((dto dict key updater failure) + (dict-update dto dict key updater failure values)) - ((dtd dict key updater failure success) - (assume (dtd? dtd)) - (assume ((dtd-ref-stx dtd dict-mutable?-id) dtd dict)) - ((dtd-ref-stx dtd dict-update-id) dtd dict key updater failure success)))) + ((dto dict key updater failure success) + (assume (dto? dto)) + (assume ((dto-ref-stx dto dict-mutable?-id) dto dict)) + ((dto-ref-stx dto dict-update-id) dto dict key updater failure success)))) (define/dict-proc-pair dict-update/default dict-update/default! dict-update/default-id) (define/dict-proc-pair dict-pop dict-pop! dict-pop-id) (define/dict-proc-pair* dict-map dict-map! dict-map-id) (define/dict-proc-pair* dict-filter dict-filter! dict-filter-id) (define/dict-proc-pair* dict-remove dict-remove! dict-remove-id) -(define/dict-proc-pair dict-alter dict-alter! dict-alter-id) +(define/dict-proc-pair dict-find-update dict-find-update! dict-find-update-id) (define/dict-proc dict-size dict-size-id) (define/dict-proc dict-count dict-count-id) (define/dict-proc dict-any dict-any-id) @@ -146,11 +146,11 @@ (define/dict-proc dict-set-accumulator dict-set-accumulator-id) (define/dict-proc dict-adjoin-accumulator dict-adjoin-accumulator-id) -(define (dtd-ref dtd procindex) - (dtd-ref-stx dtd procindex)) +(define (dto-ref dto procindex) + (dto-ref-stx dto procindex)) -(define (make-modified-dtd dtd . lst) - (define vec (vector-copy (procvec dtd))) +(define (make-modified-dto dto . lst) + (define vec (vector-copy (procvec dto))) (do ((lst lst (cddr lst))) ((null? lst)) (when (null? (cdr lst)) @@ -160,22 +160,22 @@ (unless (procedure? proc) (error "Not a procedure" proc)) (vector-set! vec proc-id proc))) - (make-dtd-private vec)) + (make-dto-private vec)) -(define (make-dtd . lst) - (apply make-modified-dtd default-dtd lst)) +(define (make-dto . lst) + (apply make-modified-dto default-dto lst)) -(define-syntax dtd-helper +(define-syntax dto-helper (syntax-rules () ((_ (arg ...) (index proc) rest ...) - (dtd-helper (arg ... index proc) rest ...)) + (dto-helper (arg ... index proc) rest ...)) ((_ (arg ...)) - (make-dtd arg ...)))) + (make-dto arg ...)))) -(define-syntax dtd +(define-syntax dto (syntax-rules () ((_ (index proc) ...) - (dtd-helper () (index proc) ...)))) + (dto-helper () (index proc) ...)))) (define (dictionary-error message . irritants) (make-dictionary-error message irritants)) diff --git a/srfi/indexes.scm b/srfi/indexes.scm index a353de8..2121558 100644 --- a/srfi/indexes.scm +++ b/srfi/indexes.scm @@ -24,7 +24,7 @@ (define dict-map-id (proc-id-inc)) (define dict-filter-id (proc-id-inc)) (define dict-remove-id (proc-id-inc)) -(define dict-alter-id (proc-id-inc)) +(define dict-find-update-id (proc-id-inc)) (define dict-size-id (proc-id-inc)) (define dict-count-id (proc-id-inc)) (define dict-any-id (proc-id-inc)) diff --git a/srfi/srfi-125-impl.scm b/srfi/srfi-125-impl.scm index 9ac64d7..1d5cf8e 100644 --- a/srfi/srfi-125-impl.scm +++ b/srfi/srfi-125-impl.scm @@ -1,4 +1,4 @@ -(define hash-table-dtd +(define hash-table-dto (let () (define-syntax guard-immutable @@ -13,30 +13,30 @@ (let ((table (t125-hash-table-copy table #f))) final-expr)))))) - (define (t125-hash-table-mutable?* dtd table) + (define (t125-hash-table-mutable?* dto table) (t125-hash-table-mutable? table)) - (define (t125-hash-table-set* dtd table . obj) + (define (t125-hash-table-set* dto table . obj) (guard-immutable table (apply t125-hash-table-set! (cons table obj)) table)) - (define (t125-hash-table-update* dtd table key updater fail success) + (define (t125-hash-table-update* dto table key updater fail success) (guard-immutable table (t125-hash-table-update! table key updater fail success) table)) - (define (t125-hash-table-update/default* dtd table key proc default) + (define (t125-hash-table-update/default* dto table key proc default) (guard-immutable table (t125-hash-table-update!/default table key proc default) table)) - (define (t125-hash-table-intern* dtd table key failure) + (define (t125-hash-table-intern* dto table key failure) (guard-immutable table (define val (t125-hash-table-intern! table key failure)) (values table val))) - (define (t125-hash-table-pop* dtd table) + (define (t125-hash-table-pop* dto table) (if (t125-hash-table-empty? table) (error "popped empty dictionary") (guard-immutable table @@ -45,7 +45,7 @@ (t125-hash-table-pop! table)) (values table key value)))) - (define (t125-hash-table-delete-all* dtd table keys) + (define (t125-hash-table-delete-all* dto table keys) (guard-immutable table (for-each (lambda (key) @@ -53,12 +53,12 @@ keys) table)) - (define (t125-hash-table-map* dtd proc table) + (define (t125-hash-table-map* dto proc table) (guard-immutable table (t125-hash-table-map! proc table) table)) - (define (t125-hash-table-filter* dtd proc table) + (define (t125-hash-table-filter* dto proc table) (guard-immutable table (t125-hash-table-prune! (lambda (key value) @@ -66,12 +66,12 @@ table) table)) - (define (t125-hash-table-remove* dtd proc table) + (define (t125-hash-table-remove* dto proc table) (guard-immutable table (t125-hash-table-prune! proc table) table)) - (define (t125-hash-table-alter* dtd table key fail success) + (define (t125-hash-table-find-update* dto table key fail success) (define (handle-success value) (define (update new-key new-value) (guard-immutable table @@ -96,55 +96,55 @@ (define default (cons #f #f)) (t125-hash-table-ref table key handle-fail handle-success)) - (define (t125-hash-table-comparator* dtd table) + (define (t125-hash-table-comparator* dto table) (make-comparator (lambda args #t) (t125-hash-table-equivalence-function table) #f (t125-hash-table-hash-function table))) - (define (t125-hash-table-copy* dtd table) + (define (t125-hash-table-copy* dto table) (t125-hash-table-copy table #t)) - (define (t125-hash-table-size* dtd table) + (define (t125-hash-table-size* dto table) (t125-hash-table-size table)) - (define (t125-hash-table-for-each* dtd proc table) + (define (t125-hash-table-for-each* dto proc table) (t125-hash-table-for-each proc table)) - (define (t125-hash-table-keys* dtd table) + (define (t125-hash-table-keys* dto table) (t125-hash-table-keys table)) - (define (t125-hash-table-values* dtd table) + (define (t125-hash-table-values* dto table) (t125-hash-table-values table)) - (define (t125-hash-table-entries* dtd table) + (define (t125-hash-table-entries* dto table) (t125-hash-table-entries table)) - (define (t125-hash-table-fold* dtd proc knil table) + (define (t125-hash-table-fold* dto proc knil table) (t125-hash-table-fold proc knil table)) - (define (t125-hash-table-map->list* dtd proc table) + (define (t125-hash-table-map->list* dto proc table) (t125-hash-table-map->list proc table)) - (define (t125-hash-table->alist* dtd table) + (define (t125-hash-table->alist* dto table) (t125-hash-table->alist table)) - (define (t125-hash-table?* dtd table) + (define (t125-hash-table?* dto table) (t125-hash-table? table)) - (define (t125-hash-table-empty?* dtd table) + (define (t125-hash-table-empty?* dto table) (t125-hash-table-empty? table)) - (define (t125-hash-table-contains?* dtd table key) + (define (t125-hash-table-contains?* dto table key) (t125-hash-table-contains? table key)) - (define (t125-hash-table-ref* dtd table key failure success) + (define (t125-hash-table-ref* dto table key failure success) (t125-hash-table-ref table key failure success)) - (define (t125-hash-table-ref/default* dtd table key default) + (define (t125-hash-table-ref/default* dto table key default) (t125-hash-table-ref/default table key default)) - (make-dtd + (make-dto dictionary?-id t125-hash-table?* dict-mutable?-id t125-hash-table-mutable?* dict-empty?-id t125-hash-table-empty?* @@ -160,7 +160,7 @@ dict-map-id t125-hash-table-map* dict-filter-id t125-hash-table-filter* dict-remove-id t125-hash-table-remove* - dict-alter-id t125-hash-table-alter* + dict-find-update-id t125-hash-table-find-update* dict-size-id t125-hash-table-size* dict-for-each-id t125-hash-table-for-each* dict-keys-id t125-hash-table-keys* diff --git a/srfi/srfi-126-impl.scm b/srfi/srfi-126-impl.scm index bb55941..e1f62f1 100644 --- a/srfi/srfi-126-impl.scm +++ b/srfi/srfi-126-impl.scm @@ -1,4 +1,4 @@ -(define srfi-126-dtd +(define srfi-126-dto (let () (define-syntax guard-immutable @@ -13,20 +13,20 @@ (let ((table (t126-hashtable-copy table #f))) final-expr)))))) - (define (prep-dtd-arg proc) - (lambda (dtd . args) + (define (prep-dto-arg proc) + (lambda (dto . args) (apply proc args))) - (define (t126-hashtable-ref* dtd table key fail success) + (define (t126-hashtable-ref* dto table key fail success) (define-values (value found?) (t126-hashtable-lookup table key)) (if found? (success value) (fail))) - (define (t126-hashtable-ref/default* dtd table key default) + (define (t126-hashtable-ref/default* dto table key default) (t126-hashtable-ref table key default)) - (define (t126-hashtable-set* dtd table . obj) + (define (t126-hashtable-set* dto table . obj) (guard-immutable table (let loop ((obj obj)) (if (null? obj) @@ -36,7 +36,7 @@ (loop (cddr obj))))) table)) - (define (t126-hashtable-delete-all* dtd table keys) + (define (t126-hashtable-delete-all* dto table keys) (guard-immutable table (for-each (lambda (key) @@ -44,17 +44,17 @@ keys) table)) - (define (t126-hashtable-intern* dtd table key default) + (define (t126-hashtable-intern* dto table key default) (guard-immutable table (define val (t126-hashtable-intern! table key default)) (values table val))) - (define (t126-hashtable-update/default* dtd table key updater default) + (define (t126-hashtable-update/default* dto table key updater default) (guard-immutable table (t126-hashtable-update! table key updater default) table)) - (define (t126-hashtable-pop* dtd table) + (define (t126-hashtable-pop* dto table) (if (t126-hashtable-empty? table) (error "popped empty dictionary") (guard-immutable table @@ -63,24 +63,24 @@ (t126-hashtable-pop! table)) (values table key value)))) - (define (t126-hashtable-update-all* dtd proc table) + (define (t126-hashtable-update-all* dto proc table) (guard-immutable table (t126-hashtable-update-all! table proc) table)) - (define (t126-hashtable-filter* dtd proc table) + (define (t126-hashtable-filter* dto proc table) (guard-immutable table (t126-hashtable-prune! table (lambda (key value) (not (proc key value)))) table)) - (define (t126-hashtable-remove* dtd proc table) + (define (t126-hashtable-remove* dto proc table) (guard-immutable table (t126-hashtable-prune! table proc) table)) - (define (t126-hashtable-alter* dtd table key fail success) + (define (t126-hashtable-find-update* dto table key fail success) (define (handle-success value) (define (update new-key new-value) (guard-immutable table @@ -108,20 +108,20 @@ (handle-fail) (handle-success found))) - (define (t126-hashtable-for-each* dtd proc table) + (define (t126-hashtable-for-each* dto proc table) (t126-hashtable-walk table proc) table) - (define (t126-hashtable-map->lset* dtd proc table) + (define (t126-hashtable-map->lset* dto proc table) (t126-hashtable-map->lset table proc)) - (define (t126-hashtable-keys* dtd table) + (define (t126-hashtable-keys* dto table) (vector->list (t126-hashtable-keys table))) - (define (t126-hashtable-values* dtd table) + (define (t126-hashtable-values* dto table) (vector->list (t126-hashtable-values table))) - (define (t126-hashtable-entries* dtd table) + (define (t126-hashtable-entries* dto table) (call-with-values (lambda () (t126-hashtable-entries table)) (lambda (keys vals) @@ -129,14 +129,14 @@ (vector->list keys) (vector->list vals))))) - (define (t126-hashtable-comparator* dtd table) + (define (t126-hashtable-comparator* dto table) #f) - (make-dtd - dictionary?-id (prep-dtd-arg t126-hashtable?) - dict-mutable?-id (prep-dtd-arg t126-hashtable-mutable?) - dict-empty?-id (prep-dtd-arg t126-hashtable-empty?) - dict-contains?-id (prep-dtd-arg t126-hashtable-contains?) + (make-dto + dictionary?-id (prep-dto-arg t126-hashtable?) + dict-mutable?-id (prep-dto-arg t126-hashtable-mutable?) + dict-empty?-id (prep-dto-arg t126-hashtable-empty?) + dict-contains?-id (prep-dto-arg t126-hashtable-contains?) dict-ref-id t126-hashtable-ref* dict-ref/default-id t126-hashtable-ref/default* dict-set-id t126-hashtable-set* @@ -147,8 +147,8 @@ dict-map-id t126-hashtable-update-all* dict-filter-id t126-hashtable-filter* dict-remove-id t126-hashtable-remove* - dict-alter-id t126-hashtable-alter* - dict-size-id (prep-dtd-arg t126-hashtable-size) + dict-find-update-id t126-hashtable-find-update* + dict-size-id (prep-dto-arg t126-hashtable-size) dict-for-each-id t126-hashtable-for-each* dict-keys-id t126-hashtable-keys* dict-values-id t126-hashtable-values* diff --git a/srfi/srfi-146-hash-impl.scm b/srfi/srfi-146-hash-impl.scm index fb8497e..822fe7f 100644 --- a/srfi/srfi-146-hash-impl.scm +++ b/srfi/srfi-146-hash-impl.scm @@ -1,11 +1,11 @@ -(define hash-mapping-dtd +(define hash-mapping-dto (let () - (define (prep-dtd-arg proc) - (lambda (dtd . args) + (define (prep-dto-arg proc) + (lambda (dto . args) (apply proc args))) - (define (hashmap-alter* dtd dict key failure success) + (define (hashmap-find-update* dto dict key failure success) (call/cc ;; escape from whole hashmap-search entirely, when success / failure ;; return something other than through passed in continuation procedures @@ -36,32 +36,32 @@ (k result)))))) new-dict))) - (make-dtd - dictionary?-id (prep-dtd-arg hashmap?) + (make-dto + dictionary?-id (prep-dto-arg hashmap?) dict-mutable?-id (lambda _ #f) - dict-empty?-id (prep-dtd-arg hashmap-empty?) - dict-contains?-id (prep-dtd-arg hashmap-contains?) - dict-ref-id (prep-dtd-arg hashmap-ref) - dict-ref/default-id (prep-dtd-arg hashmap-ref/default) - dict-set-id (prep-dtd-arg hashmap-set) - dict-adjoin-id (prep-dtd-arg hashmap-adjoin) - dict-delete-id (prep-dtd-arg hashmap-delete) - dict-delete-all-id (prep-dtd-arg hashmap-delete-all) - dict-replace-id (prep-dtd-arg hashmap-replace) - dict-intern-id (prep-dtd-arg hashmap-intern) - dict-update-id (prep-dtd-arg hashmap-update) - dict-update/default-id (prep-dtd-arg hashmap-update/default) - dict-pop-id (prep-dtd-arg hashmap-pop) - dict-filter-id (prep-dtd-arg hashmap-filter) - dict-remove-id (prep-dtd-arg hashmap-remove) - dict-alter-id hashmap-alter* - dict-size-id (prep-dtd-arg hashmap-size) - dict-for-each-id (prep-dtd-arg hashmap-for-each) - dict-count-id (prep-dtd-arg hashmap-count) - dict-keys-id (prep-dtd-arg hashmap-keys) - dict-values-id (prep-dtd-arg hashmap-values) - dict-entries-id (prep-dtd-arg hashmap-entries) - dict-fold-id (prep-dtd-arg hashmap-fold) - dict-map->list-id (prep-dtd-arg hashmap-map->list) - dict->alist-id (prep-dtd-arg hashmap->alist) - dict-comparator-id (prep-dtd-arg hashmap-key-comparator)))) + dict-empty?-id (prep-dto-arg hashmap-empty?) + dict-contains?-id (prep-dto-arg hashmap-contains?) + dict-ref-id (prep-dto-arg hashmap-ref) + dict-ref/default-id (prep-dto-arg hashmap-ref/default) + dict-set-id (prep-dto-arg hashmap-set) + dict-adjoin-id (prep-dto-arg hashmap-adjoin) + dict-delete-id (prep-dto-arg hashmap-delete) + dict-delete-all-id (prep-dto-arg hashmap-delete-all) + dict-replace-id (prep-dto-arg hashmap-replace) + dict-intern-id (prep-dto-arg hashmap-intern) + dict-update-id (prep-dto-arg hashmap-update) + dict-update/default-id (prep-dto-arg hashmap-update/default) + dict-pop-id (prep-dto-arg hashmap-pop) + dict-filter-id (prep-dto-arg hashmap-filter) + dict-remove-id (prep-dto-arg hashmap-remove) + dict-find-update-id hashmap-find-update* + dict-size-id (prep-dto-arg hashmap-size) + dict-for-each-id (prep-dto-arg hashmap-for-each) + dict-count-id (prep-dto-arg hashmap-count) + dict-keys-id (prep-dto-arg hashmap-keys) + dict-values-id (prep-dto-arg hashmap-values) + dict-entries-id (prep-dto-arg hashmap-entries) + dict-fold-id (prep-dto-arg hashmap-fold) + dict-map->list-id (prep-dto-arg hashmap-map->list) + dict->alist-id (prep-dto-arg hashmap->alist) + dict-comparator-id (prep-dto-arg hashmap-key-comparator)))) diff --git a/srfi/srfi-146-impl.scm b/srfi/srfi-146-impl.scm index b504e5f..ad6b629 100644 --- a/srfi/srfi-146-impl.scm +++ b/srfi/srfi-146-impl.scm @@ -1,11 +1,11 @@ -(define mapping-dtd +(define mapping-dto (let () - (define (prep-dtd-arg proc) - (lambda (dtd . args) + (define (prep-dto-arg proc) + (lambda (dto . args) (apply proc args))) - (define (mapping-alter* dtd dict key failure success) + (define (mapping-find-update* dto dict key failure success) (call/cc ;; escape from whole hashmap-search entirely, when success / failure ;; return something other than through passed in continuation procedures @@ -36,32 +36,32 @@ (k result)))))) new-dict))) - (make-dtd - dictionary?-id (prep-dtd-arg mapping?) + (make-dto + dictionary?-id (prep-dto-arg mapping?) dict-mutable?-id (lambda _ #f) - dict-empty?-id (prep-dtd-arg mapping-empty?) - dict-contains?-id (prep-dtd-arg mapping-contains?) - dict-ref-id (prep-dtd-arg mapping-ref) - dict-ref/default-id (prep-dtd-arg mapping-ref/default) - dict-set-id (prep-dtd-arg mapping-set) - dict-adjoin-id (prep-dtd-arg mapping-adjoin) - dict-delete-id (prep-dtd-arg mapping-delete) - dict-delete-all-id (prep-dtd-arg mapping-delete-all) - dict-replace-id (prep-dtd-arg mapping-replace) - dict-intern-id (prep-dtd-arg mapping-intern) - dict-update-id (prep-dtd-arg mapping-update) - dict-update/default-id (prep-dtd-arg mapping-update/default) - dict-pop-id (prep-dtd-arg mapping-pop) - dict-filter-id (prep-dtd-arg mapping-filter) - dict-remove-id (prep-dtd-arg mapping-remove) - dict-alter-id mapping-alter* - dict-size-id (prep-dtd-arg mapping-size) - dict-for-each-id (prep-dtd-arg mapping-for-each) - dict-count-id (prep-dtd-arg mapping-count) - dict-keys-id (prep-dtd-arg mapping-keys) - dict-values-id (prep-dtd-arg mapping-values) - dict-entries-id (prep-dtd-arg mapping-entries) - dict-fold-id (prep-dtd-arg mapping-fold) - dict-map->list-id (prep-dtd-arg mapping-map->list) - dict->alist-id (prep-dtd-arg mapping->alist) - dict-comparator-id (prep-dtd-arg mapping-key-comparator)))) + dict-empty?-id (prep-dto-arg mapping-empty?) + dict-contains?-id (prep-dto-arg mapping-contains?) + dict-ref-id (prep-dto-arg mapping-ref) + dict-ref/default-id (prep-dto-arg mapping-ref/default) + dict-set-id (prep-dto-arg mapping-set) + dict-adjoin-id (prep-dto-arg mapping-adjoin) + dict-delete-id (prep-dto-arg mapping-delete) + dict-delete-all-id (prep-dto-arg mapping-delete-all) + dict-replace-id (prep-dto-arg mapping-replace) + dict-intern-id (prep-dto-arg mapping-intern) + dict-update-id (prep-dto-arg mapping-update) + dict-update/default-id (prep-dto-arg mapping-update/default) + dict-pop-id (prep-dto-arg mapping-pop) + dict-filter-id (prep-dto-arg mapping-filter) + dict-remove-id (prep-dto-arg mapping-remove) + dict-find-update-id mapping-find-update* + dict-size-id (prep-dto-arg mapping-size) + dict-for-each-id (prep-dto-arg mapping-for-each) + dict-count-id (prep-dto-arg mapping-count) + dict-keys-id (prep-dto-arg mapping-keys) + dict-values-id (prep-dto-arg mapping-values) + dict-entries-id (prep-dto-arg mapping-entries) + dict-fold-id (prep-dto-arg mapping-fold) + dict-map->list-id (prep-dto-arg mapping-map->list) + dict->alist-id (prep-dto-arg mapping->alist) + dict-comparator-id (prep-dto-arg mapping-key-comparator)))) diff --git a/srfi/srfi-69-impl.scm b/srfi/srfi-69-impl.scm index 734c6b4..c61036e 100644 --- a/srfi/srfi-69-impl.scm +++ b/srfi/srfi-69-impl.scm @@ -1,21 +1,21 @@ -(define srfi-69-dtd +(define srfi-69-dto (let () - (define (prep-dtd-arg proc) - (lambda (dtd . args) + (define (prep-dto-arg proc) + (lambda (dto . args) (apply proc args))) - (define (t69-hash-table-mutable?* dtd table) + (define (t69-hash-table-mutable?* dto table) #t) - (define (t69-hash-table-ref* dtd table key fail success) + (define (t69-hash-table-ref* dto table key fail success) (define default (cons #f #f)) (define found (t69-hash-table-ref/default table key default)) (if (eq? found default) (fail) (success found))) - (define (t69-hash-table-set!* dtd table . obj) + (define (t69-hash-table-set!* dto table . obj) (let loop ((obj obj)) (if (null? obj) table @@ -23,36 +23,36 @@ (t69-hash-table-set! table (car obj) (cadr obj)) (loop (cddr obj)))))) - (define (t69-hash-table-update!/default* dtd table key proc default) + (define (t69-hash-table-update!/default* dto table key proc default) (t69-hash-table-update!/default table key proc default) table) - (define (t69-hash-table-delete-all!* dtd table keys) + (define (t69-hash-table-delete-all!* dto table keys) (for-each (lambda (key) (t69-hash-table-delete! table key)) keys) table) - (define (t69-hash-table-foreach* dtd proc table) + (define (t69-hash-table-foreach* dto proc table) (t69-hash-table-walk table proc)) - (define (t69-hash-table-map!* dtd proc table) + (define (t69-hash-table-map!* dto proc table) (t69-hash-table-walk table (lambda (key value) (t69-hash-table-set! table key (proc key value)))) table) - (define (t69-hash-table-filter!* dtd proc table) + (define (t69-hash-table-filter!* dto proc table) (t69-hash-table-walk table (lambda (key value) (unless (proc key value) (t69-hash-table-delete! table key)))) table) - (define (t69-hash-table-fold* dtd proc knil table) + (define (t69-hash-table-fold* dto proc knil table) (t69-hash-table-fold table proc knil)) - (define (t69-hash-table-alter!* dtd table key fail success) + (define (t69-hash-table-find-update!* dto table key fail success) (define (handle-success value) (define (update new-key new-value) (unless (eq? new-key key) @@ -77,29 +77,29 @@ (handle-fail) (handle-success found))) - (define (t69-hash-table-comparator* dtd table) + (define (t69-hash-table-comparator* dto table) (make-comparator (lambda args #t) (or (t69-hash-table-equivalence-function table) equal?) #f (t69-hash-table-hash-function table))) - (make-dtd - dictionary?-id (prep-dtd-arg t69-hash-table?) + (make-dto + dictionary?-id (prep-dto-arg t69-hash-table?) dict-mutable?-id t69-hash-table-mutable?* dict-ref-id t69-hash-table-ref* - dict-ref/default-id (prep-dtd-arg t69-hash-table-ref/default) + dict-ref/default-id (prep-dto-arg t69-hash-table-ref/default) dict-set-id t69-hash-table-set!* dict-delete-all-id t69-hash-table-delete-all!* - dict-contains?-id (prep-dtd-arg t69-hash-table-exists?) + dict-contains?-id (prep-dto-arg t69-hash-table-exists?) dict-update/default-id t69-hash-table-update!/default* - dict-size-id (prep-dtd-arg t69-hash-table-size) - dict-keys-id (prep-dtd-arg t69-hash-table-keys) - dict-values-id (prep-dtd-arg t69-hash-table-values) + dict-size-id (prep-dto-arg t69-hash-table-size) + dict-keys-id (prep-dto-arg t69-hash-table-keys) + dict-values-id (prep-dto-arg t69-hash-table-values) dict-map-id t69-hash-table-map!* dict-filter-id t69-hash-table-filter!* dict-for-each-id t69-hash-table-foreach* dict-fold-id t69-hash-table-fold* - dict->alist-id (prep-dtd-arg t69-hash-table->alist) - dict-alter-id t69-hash-table-alter!* + dict->alist-id (prep-dto-arg t69-hash-table->alist) + dict-find-update-id t69-hash-table-find-update!* dict-comparator-id t69-hash-table-comparator*))) |
