summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar John Cowan 2022-03-15 15:32:54 -0400
committerGravatar GitHub 2022-03-15 15:32:54 -0400
commita7f2c6a51139c210e4d62ab1447830cc525de21a (patch)
tree2c15cebeda8c756bb9139a4cd3ef786266c02604
parentUpdate srfi-225.html (diff)
parentfix srfi 125 implementation (diff)
Merge pull request #3 from arvyy/master
Implementation update
-rw-r--r--srfi-225-test.scm452
-rw-r--r--srfi-225.html24
-rw-r--r--srfi/225.sld82
-rw-r--r--srfi/alist-impl.scm12
-rw-r--r--srfi/default-impl.scm256
-rw-r--r--srfi/externals.scm41
-rw-r--r--srfi/indexes.scm12
-rw-r--r--srfi/srfi-125-impl.scm97
-rw-r--r--srfi/srfi-126-impl.scm76
-rw-r--r--srfi/srfi-146-hash-impl.scm9
-rw-r--r--srfi/srfi-146-impl.scm9
-rw-r--r--srfi/srfi-69-impl.scm10
12 files changed, 498 insertions, 582 deletions
diff --git a/srfi-225-test.scm b/srfi-225-test.scm
index 1ef4231..8a81504 100644
--- a/srfi-225-test.scm
+++ b/srfi-225-test.scm
@@ -75,6 +75,9 @@
(call/cc (lambda (cont)
(with-exception-handler
(lambda (err)
+ (when expect-success
+ (display err)
+ (newline))
(unless expect-success
(cont #t)))
(lambda ()
@@ -150,7 +153,8 @@
(test-skip 1))
(test-group
"dict-set!"
- (define d (dict-set! dto (alist->dict '((a . b))) 'a 'c 'a2 'b2))
+ (define d (alist->dict '((a . b))))
+ (dict-set! dto d 'a 'c 'a2 'b2)
(test-equal 'c (dict-ref dto d 'a ))
(test-equal 'b2 (dict-ref dto d 'a2)))
@@ -168,7 +172,8 @@
(test-skip 1))
(test-group
"dict-adjoin!"
- (define d (dict-adjoin! dto (alist->dict '((a . b))) 'a 'c 'a2 'b2))
+ (define d (alist->dict '((a . b))))
+ (dict-adjoin! dto d 'a 'c 'a2 'b2)
(test-equal 'b (dict-ref dto d 'a))
(test-equal 'b2 (dict-ref dto d 'a2)))
@@ -185,7 +190,8 @@
(test-skip 1))
(test-group
"dict-delete!"
- (define d (dict-delete! dto (alist->dict '((a . b) (c . d))) 'a 'b))
+ (define d (alist->dict '((a . b) (c . d))))
+ (dict-delete! dto d 'a 'b)
(test-equal (dict->alist dto d) '((c . d))))
(when mutable?
@@ -201,7 +207,8 @@
(test-skip 1))
(test-group
"dict-delete-all!"
- (define d (dict-delete-all! dto (alist->dict '((a . b) (c . d))) '(a b)))
+ (define d (alist->dict '((a . b) (c . d))))
+ (dict-delete-all! dto d '(a b))
(test-equal (dict->alist dto d) '((c . d))))
(when mutable?
@@ -218,7 +225,8 @@
(test-skip 1))
(test-group
"dict-replace!"
- (define d (dict-replace! dto (alist->dict '((a . b) (c . d))) 'a 'b2))
+ (define d (alist->dict '((a . b) (c . d))))
+ (dict-replace! dto d 'a 'b2)
(test-equal 'b2 (dict-ref dto d 'a))
(test-equal 'd (dict-ref dto d 'c)))
@@ -250,19 +258,17 @@
"dict-intern!"
;; intern existing
(let ()
- (define-values
- (d value)
- (dict-intern! dto (alist->dict '((a . b))) 'a (lambda () 'd)))
- (test-equal 'b (dict-ref dto d 'a))
- (test-equal 'b value))
+ (define d (alist->dict '((a . b))))
+ (define value (dict-intern! dto d 'a (lambda () 'd)))
+ (test-equal 'b (dict-ref dto d 'a))
+ (test-equal 'b value))
;; intern missing
(let ()
- (define-values
- (d value)
- (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)))
+ (define d (alist->dict '((a . b))))
+ (define value (dict-intern! dto d '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?
(test-skip 1))
@@ -294,19 +300,21 @@
"dict-update!"
;; update existing
(let ()
- (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 dto d 'a)))
+ (define d (alist->dict '((a . "b"))))
+ (dict-update! dto d 'a
+ (lambda (value)
+ (string-append value "2"))
+ error
+ (lambda (x) (string-append x "1")))
+ (test-equal "b12" (dict-ref dto d 'a)))
;; update missing
(let ()
- (define d (dict-update! dto (alist->dict '((a . "b"))) 'c
- (lambda (value)
- (string-append value "2"))
- (lambda () "d1")
- (lambda (x) (string-append x "1"))))
+ (define d (alist->dict '((a . "b"))))
+ (dict-update! dto d 'c
+ (lambda (value)
+ (string-append value "2"))
+ (lambda () "d1")
+ (lambda (x) (string-append x "1")))
(test-equal "d12" (dict-ref dto d 'c))))
(when mutable?
@@ -338,19 +346,21 @@
"dict-update/default!"
;; update existing
(let ()
- (define d (dict-update/default! dto (alist->dict '((a . "b"))) 'a
- (lambda (value)
- (string-append value "2"))
- "d1"))
+ (define d (alist->dict '((a . "b"))))
+ (dict-update/default! dto d 'a
+ (lambda (value)
+ (string-append value "2"))
+ "d1")
(test-equal "b2" (dict-ref dto d 'a)))
;; update missing
(let ()
- (define d (dict-update/default! dto (alist->dict '((a . "b"))) 'c
- (lambda (value)
- (string-append value "2"))
- "d1"))
- (test-equal "d12" (dict-ref dto d 'c))))
+ (define d (alist->dict '((a . "b"))))
+ (dict-update/default! dto d 'c
+ (lambda (value)
+ (string-append value "2"))
+ "d1")
+ (test-equal "d12" (dict-ref dto d 'c))))
(when mutable?
(test-skip 1))
@@ -376,16 +386,17 @@
(test-skip 1))
(test-group
"dict-pop!"
+ (define d (alist->dict '((a . b) (c . d))))
(define-values
- (new-dict key value)
- (dict-pop! dto (alist->dict '((a . b) (c . d)))))
+ (key value)
+ (dict-pop! dto d))
(test-assert
(or
- (and (equal? (dict->alist dto new-dict) '((c . d)))
+ (and (equal? (dict->alist dto d) '((c . d)))
(equal? key 'a)
(equal? value 'b))
- (and (equal? (dict->alist dto new-dict) '((a . b)))
+ (and (equal? (dict->alist dto d) '((a . b)))
(equal? key 'c)
(equal? value 'd)))))
@@ -407,10 +418,11 @@
(test-skip 1))
(test-group
"dict-map!"
- (define d (dict-map! dto
- (lambda (key value)
- (string-append value "2"))
- (alist->dict '((a . "a") (b . "b")))))
+ (define d (alist->dict '((a . "a") (b . "b"))))
+ (dict-map! dto
+ (lambda (key value)
+ (string-append value "2"))
+ d)
(test-equal "a2" (dict-ref dto d 'a))
(test-equal "b2" (dict-ref dto d 'b)))
@@ -431,10 +443,11 @@
(test-skip 1))
(test-group
"dict-filter!"
- (define d (dict-filter! dto
- (lambda (key value)
- (equal? value 'b))
- (alist->dict '((a . b) (c . d)))))
+ (define d (alist->dict '((a . b) (c . d))))
+ (dict-filter! dto
+ (lambda (key value)
+ (equal? value 'b))
+ d)
(test-equal '((a . b)) (dict->alist dto d)))
(when mutable?
@@ -453,10 +466,11 @@
(test-skip 1))
(test-group
"dict-remove!"
- (define d (dict-remove! dto
- (lambda (key value)
- (equal? value 'b))
- (alist->dict '((a . b) (c . d)))))
+ (define d (alist->dict '((a . b) (c . d))))
+ (dict-remove! dto
+ (lambda (key value)
+ (equal? value 'b))
+ d)
(test-equal '((c . d)) (dict->alist dto d)))
(when mutable?
@@ -513,40 +527,44 @@
"dict-find-update!"
;; ignore
(let ()
- (define dict (dict-find-update! dto (alist->dict '((a . b))) 'c
+ (define dict (alist->dict '((a . b))))
+ (dict-find-update! dto dict 'c
(lambda (insert ignore)
(ignore))
(lambda args
- (error "shouldn't happen"))))
- (test-equal '((a . b)) (dict->alist dto dict)))
+ (error "shouldn't happen")))
+ (test-equal '((a . b)) (dict->alist dto dict)))
;; insert
(let ()
- (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 dto dict 'a))
- (test-equal 'd (dict-ref dto dict 'c)))
+ (define dict (alist->dict '((a . b))))
+ (dict-find-update! dto dict 'c
+ (lambda (insert ignore)
+ (insert 'd))
+ (lambda args
+ (error "shouldn't happen")))
+ (test-equal 'b (dict-ref dto dict 'a))
+ (test-equal 'd (dict-ref dto dict 'c)))
;; update
(let ()
- (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))))
+ (define dict (alist->dict '((a . b))))
+ (dict-find-update! dto dict 'a
+ (lambda args
+ (error "shouldn't happen"))
+ (lambda (key value update delete)
+ (update 'a2 'b2)))
(test-equal '((a2 . b2)) (dict->alist dto dict)))
;; delete
(let ()
- (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 dto dict))))
+ (define dict (alist->dict '((a . b) (c . d))))
+ (dict-find-update! dto dict 'a
+ (lambda args
+ (error "shouldn't happen"))
+ (lambda (key value update delete)
+ (delete)))
+ (test-equal '((c . d)) (dict->alist dto dict))))
(test-group
"dict-size"
@@ -635,15 +653,49 @@
(test-group
"dict-fold"
- (define value
- (dict-fold dto
- (lambda (key value acc)
- (append acc (list key value)))
- '()
- (alist->dict '((a . b) (c . d)))))
- (test-assert
- (or (equal? '(a b c d) value)
- (equal? '(c d a b) value))))
+
+ ;; simple case
+ (let ()
+ (define value
+ (dict-fold dto
+ (lambda (key value acc)
+ (append acc (list key value)))
+ '()
+ (alist->dict '((a . b) (c . d)))))
+ (test-assert
+ (or (equal? '(a b c d) value)
+ (equal? '(c d a b) value))))
+
+ (let ()
+
+ ;; continuation captured in a middle of fold
+ (define k #f)
+ (define pass 0)
+
+ (define value
+ (dict-fold dto
+ (lambda (key value acc)
+ ;; check fold only starts once -- further passes enter in a middle
+ (test-assert (not (and k
+ (null? acc))))
+ ;; capture continuation on second fold iteration
+ (when (and (not k)
+ (not (null? acc)))
+ (test-assert
+ (or (equal? '(a b) acc)
+ (equal? '(c d) acc)))
+ (call/cc (lambda (cont) (set! k cont))))
+ (append acc (list key value)))
+ '()
+ (alist->dict '((a . b) (c . d)))))
+
+ (test-assert
+ (or (equal? '(a b c d) value)
+ (equal? '(c d a b) value)))
+
+ (when (< pass 3)
+ (set! pass (+ 1 pass))
+ (k #t))))
(test-group
"dict-map->list"
@@ -683,140 +735,78 @@
(2 . b)
(3 . c)
(4 . d)))))
- '(1 2 3 4)))
-
- (test-group
- "dict-for-each<"
- (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '())))
- (ordering (and cmp (comparator-ordered? cmp))))
- ordering)
- (lambda (proc)
- (dict-for-each< dto
- proc
- (alist->dict '((1 . a)
- (2 . b)
- (3 . c)
- (4 . d)))
- 3))
- '(1 2)))
-
- (test-group
- "dict-for-each<="
- (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '())))
- (ordering (and cmp (comparator-ordered? cmp))))
- ordering)
- (lambda (proc)
- (dict-for-each<= dto
- proc
- (alist->dict '((1 . a)
- (2 . b)
- (3 . c)
- (4 . d)))
- 3))
- '(1 2 3)))
-
- (test-group
- "dict-for-each>"
+ '(1 2 3 4))
+
(test-for-each (let* ((cmp (dict-comparator dto (alist->dict '())))
(ordering (and cmp (comparator-ordered? cmp))))
ordering)
- (lambda (proc)
- (dict-for-each> dto
- proc
- (alist->dict '((1 . a)
- (2 . b)
- (3 . c)
- (4 . d)))
- 2))
- '(3 4)))
-
- (test-group
- "dict-for-each>="
- (test-for-each (let* ((cmp (dict-comparator dto (alist->dict '())))
- (ordering (and cmp (comparator-ordered? cmp))))
- ordering)
- (lambda (proc)
- (dict-for-each>= dto
- proc
- (alist->dict '((1 . a)
- (2 . b)
- (3 . c)
- (4 . d)))
- 2))
- '(2 3 4)))
-
- (test-group
- "dict-for-each-in-open-interval"
- (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 dto
- proc
- (alist->dict '((1 . a)
- (2 . b)
- (3 . c)
- (4 . d)))
- 1 4))
- '(2 3)))
+ (lambda (proc)
+ (dict-for-each dto
+ proc
+ (alist->dict '((1 . a)
+ (2 . b)
+ (3 . c)
+ (4 . d)))
+ 2))
+ '(2 3 4))
- (test-group
- "dict-for-each-in-closed-interval"
(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 dto
- proc
- (alist->dict '((1 . a)
- (2 . b)
- (3 . c)
- (4 . d)))
- 1 4))
- '(1 2 3 4)))
+ (lambda (proc)
+ (dict-for-each dto
+ proc
+ (alist->dict '((1 . a)
+ (2 . b)
+ (3 . c)
+ (4 . d)))
+ 2
+ 3))
+ '(2 3)))
+
+ (test-group
+ "dict->generator"
+ (test-for-each #t
+ (lambda (proc)
+ (generator-for-each
+ (lambda (entry)
+ (proc (car entry) (cdr entry)))
+ (dict->generator dto (alist->dict '((1 . a)
+ (2 . b)
+ (3 . c)
+ (4 . d))))))
+ '(1 2 3 4))
- (test-group
- "dict-for-each-in-open-closed-interval"
(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 dto
- proc
- (alist->dict '((1 . a)
- (2 . b)
- (3 . c)
- (4 . d)))
- 1 4))
- '(2 3 4)))
+ (lambda (proc)
+ (generator-for-each
+ (lambda (entry)
+ (proc (car entry) (cdr entry)))
+ (dict->generator dto (alist->dict '((1 . a)
+ (2 . b)
+ (3 . c)
+ (4 . d)))
+ 2)))
+ '(2 3 4))
- (test-group
- "dict-for-each-in-closed-open-interval"
(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 dto
- proc
- (alist->dict '((1 . a)
- (2 . b)
- (3 . c)
- (4 . d)))
- 1 4))
- '(1 2 3)))
-
- (test-group
- "make-dict-generator"
- (test-for-each #t
- (lambda (proc)
- (generator-for-each
- (lambda (entry)
- (proc (car entry) (cdr entry)))
- (make-dict-generator dto (alist->dict '((1 . a)
- (2 . b)
- (3 . c))))))
- '(1 2 3)))
+ (lambda (proc)
+ (generator-for-each
+ (lambda (entry)
+ (proc (car entry) (cdr entry)))
+ (dict->generator dto (alist->dict '((1 . a)
+ (2 . b)
+ (3 . c)
+ (4 . d)))
+ 2 3)))
+ '(2 3)))
+ (when mutable?
+ (test-skip 1))
(test-group
"dict-set-accumulator"
(define acc (dict-set-accumulator dto (alist->dict '())))
@@ -824,7 +814,19 @@
(acc (cons 2 'b))
(acc (cons 2 'c))
(test-assert (dict=? dto equal? (acc (eof-object)) (alist->dict '((1 . a) (2 . c))))))
+
+ (unless mutable?
+ (test-skip 1))
+ (test-group
+ "dict-set!-accumulator"
+ (define acc (dict-set!-accumulator dto (alist->dict '())))
+ (acc (cons 1 'a))
+ (acc (cons 2 'b))
+ (acc (cons 2 'c))
+ (test-assert (dict=? dto equal? (acc (eof-object)) (alist->dict '((1 . a) (2 . c))))))
+ (when mutable?
+ (test-skip 1))
(test-group
"dict-adjoin-accumulator"
(define acc (dict-adjoin-accumulator dto (alist->dict '())))
@@ -832,6 +834,16 @@
(acc (cons 2 'b))
(acc (cons 2 'c))
(test-assert (dict=? dto equal? (acc (eof-object)) (alist->dict '((1 . a) (2 . b))))))
+
+ (unless mutable?
+ (test-skip 1))
+ (test-group
+ "dict-adjoin!-accumulator"
+ (define acc (dict-adjoin!-accumulator dto (alist->dict '())))
+ (acc (cons 1 'a))
+ (acc (cons 2 'b))
+ (acc (cons 2 'c))
+ (test-assert (dict=? dto equal? (acc (eof-object)) (alist->dict '((1 . a) (2 . b))))))
;; check all procs were called
(for-each
@@ -849,10 +861,10 @@
(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-pure?-id (dto-ref alist-dto dict-pure?-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-map-id (dto-ref alist-dto dict-map-id)
dict-comparator-id (dto-ref alist-dto dict-comparator-id)))
(do-test
minimal-alist-dto
@@ -894,9 +906,9 @@
(else))
(cond-expand
- ((library (srf 125))
+ ((library (srfi 125))
(test-group
- "srfi-125 mutable"
+ "srfi-125"
(do-test
hash-table-dto
(lambda (alist)
@@ -907,26 +919,13 @@
alist)
table)
(make-default-comparator)
- #t))
- (test-group
- "srfi-125 immutable"
- (do-test
- hash-table-dto
- (lambda (alist)
- (define table (t125-hash-table-empty-copy (t125-make-hash-table equal?)))
- (for-each
- (lambda (pair)
- (t125-hash-table-set! table (car pair) (cdr pair)))
- alist)
- (t125-hash-table-copy table #f))
- (make-default-comparator)
- #f)))
+ #t)))
(else))
(cond-expand
((library (srfi 126))
(test-group
- "srfi-126 (r6rs) mutable"
+ "srfi-126 (r6rs)"
(do-test
srfi-126-dto
(lambda (alist)
@@ -937,20 +936,7 @@
alist)
table)
(make-default-comparator)
- #t))
- (test-group
- "srfi-126 (r6rs) immutable"
- (do-test
- srfi-126-dto
- (lambda (alist)
- (define table (t126-make-eqv-hashtable))
- (for-each
- (lambda (pair)
- (t126-hashtable-set! table (car pair) (cdr pair)))
- alist)
- (t126-hashtable-copy table #f))
- (make-default-comparator)
- #f)))
+ #t)))
(else))
(cond-expand
diff --git a/srfi-225.html b/srfi-225.html
index 48fed8b..29ebeba 100644
--- a/srfi-225.html
+++ b/srfi-225.html
@@ -384,8 +384,6 @@ one for each of the four procedures:
</pre></blockquote>
<p><code>(dict-&gt;alist</code>&nbsp;<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>
-<code>dict-filter</code>, <code>dict-remove</code>,
-and <code>dict-find-update</code>.
</p>
<p><code>(dict-comparator</code>&nbsp;<em>dto dict</em><code>)</code></p>
<p>Return a comparator representing the type predicate, equality predicate,
@@ -573,11 +571,6 @@ new dictionary types that may not have complete dictionary APIs:</p>
<dd>dict-delete-all</dd>
<dd>dict-empty?</dd>
- <dt>dict-map</dt>
- <dd>dict-keys</dd>
- <dd>dict-ref</dd>
- <dd>dict-replace</dd>
-
<dt>dict-filter</dt>
<dd>dict-keys</dd>
<dd>dict-ref</dd>
@@ -610,23 +603,24 @@ new dictionary types that may not have complete dictionary APIs:</p>
<dt>dict-map-&gt;list</dt>
<dd>dict-fold</dd>
- <dd>dict-map-&gt;list</dd>
-
- <dt>dict-for-each&gt;</dt>
- <dd>dict-for-each</dd>
-
- <dt>dict-for-each&gt;=</dt>
- <dd>dict-for-each</dd>
+ <dt>dict-for-each</dt>
+ <dd>dict-map or dict-map!</dd>
<dt>dict-&gt;generator</dt>
- <dd>dict-entries</dd>
+ <dd>dict-for-each</dd>
<dt>dict-set-accumulator</dt>
<dd>dict-set</dd>
+ <dt>dict-set!-accumulator</dt>
+ <dd>dict-set!</dd>
+
<dt>dict-adjoin-accumulator</dt>
<dd>dict-set</dd>
+ <dt>dict-adjoin!-accumulator</dt>
+ <dd>dict-adjoin!</dd>
+
</dl>
<h2 id="acknowledgements">Acknowledgements</h2>
diff --git a/srfi/225.sld b/srfi/225.sld
index 94699e7..b16f994 100644
--- a/srfi/225.sld
+++ b/srfi/225.sld
@@ -18,7 +18,7 @@
dict-empty?
dict-contains?
dict=?
- dict-mutable?
+ dict-pure?
;; lookup
dict-ref
@@ -67,19 +67,11 @@
;; iteration
dict-for-each
- dict-for-each<
- dict-for-each<=
- dict-for-each>
- dict-for-each>=
- dict-for-each-in-open-interval
- dict-for-each-in-closed-interval
- dict-for-each-in-open-closed-interval
- dict-for-each-in-closed-open-interval
-
- ;; generator procedures
- make-dict-generator
+ dict->generator
dict-set-accumulator
+ dict-set!-accumulator
dict-adjoin-accumulator
+ dict-adjoin!-accumulator
;; dictionary type descriptors
dto?
@@ -95,49 +87,47 @@
dictionary-irritants
;; proc indeces
+
+ ;; required
dictionary?-id
- dict-empty?-id
- dict-contains?-id
- dict=?-id
- dict-mutable?-id
- dict-ref-id
- dict-ref/default-id
- dict-set-id
- dict-adjoin-id
- dict-delete-id
- dict-delete-all-id
- dict-replace-id
- dict-intern-id
- dict-update-id
- dict-update/default-id
- dict-pop-id
+ dict-find-update-id
+ dict-comparator-id
dict-map-id
- dict-filter-id
+ dict-pure?-id
dict-remove-id
- dict-find-update-id
dict-size-id
- dict-count-id
+
+ ;; extra
+ dict->alist-id
+ dict-adjoin-accumulator-id
+ dict-adjoin-id
dict-any-id
- dict-every-id
- dict-keys-id
- dict-values-id
+ dict-contains?-id
+ dict-count-id
+ dict-delete-all-id
+ dict-delete-id
+ dict-empty?-id
dict-entries-id
+ dict-every-id
+ dict-filter-id
dict-fold-id
- dict-map->list-id
- dict->alist-id
- dict-comparator-id
dict-for-each-id
- dict-for-each<-id
- dict-for-each<=-id
- dict-for-each>-id
- dict-for-each>=-id
- dict-for-each-in-open-interval-id
- dict-for-each-in-closed-interval-id
- dict-for-each-in-open-closed-interval-id
- dict-for-each-in-closed-open-interval-id
- make-dict-generator-id
+ dict-intern-id
+ dict-keys-id
+ dict-map->list-id
+ dict-map-id
+ dict-pop-id
+ dict-ref-id
+ dict-ref/default-id
+ dict-remove-id
+ dict-replace-id
dict-set-accumulator-id
- dict-adjoin-accumulator-id
+ dict-set-id
+ dict-update-id
+ dict-update/default-id
+ dict-values-id
+ dict=?-id
+ dict->generator-id
;; basic DTOs
alist-eqv-dto
diff --git a/srfi/alist-impl.scm b/srfi/alist-impl.scm
index 19d42b6..80b449d 100644
--- a/srfi/alist-impl.scm
+++ b/srfi/alist-impl.scm
@@ -5,8 +5,8 @@
(or (null? l)
(pair? (car l)))))
- (define (alist-mutable? dto alist)
- #f)
+ (define (alist-pure? dto alist)
+ #t)
(define (alist-map dto proc alist)
(map
@@ -62,11 +62,6 @@
(define (alist-size dto alist)
(length alist))
- (define (alist-foreach dto proc alist)
- (define (proc* e)
- (proc (car e) (cdr e)))
- (for-each proc* alist))
-
(define (alist->alist dto alist)
alist)
@@ -75,12 +70,11 @@
(make-dto
dictionary?-id alist?
- dict-mutable?-id alist-mutable?
+ dict-pure?-id alist-pure?
dict-map-id alist-map
dict-filter-id alist-filter
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))
diff --git a/srfi/default-impl.scm b/srfi/default-impl.scm
index dea21ee..24b20d6 100644
--- a/srfi/default-impl.scm
+++ b/srfi/default-impl.scm
@@ -9,34 +9,49 @@
(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-pure? (not-implemented "dict-pure?"))
(define default-dict-size (not-implemented "dict-size"))
(define default-dict-find-update (not-implemented "dict-find-update"))
(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)))
+ (if (dict-pure? dto dict)
+ (dict-find-update dto dict key fail success)
+ (dict-find-update! dto dict key fail success)))
+
+ (define (dict-find-update*/dict dto dict key fail success)
+ (if (dict-pure? dto dict)
+ (dict-find-update dto dict key fail success)
+ (begin
+ (dict-find-update! dto dict key fail success)
+ dict)))
(define (dict-delete-all* dto dict keys)
- (if (dict-mutable? dto dict)
- (dict-delete-all! dto dict keys)
- (dict-delete-all dto dict keys)))
+ (if (dict-pure? dto dict)
+ (dict-delete-all dto dict keys)
+ (begin
+ (dict-delete-all! dto dict keys)
+ dict)))
(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)))
+ (if (dict-pure? dto dict)
+ (dict-update dto dict key updater fail success)
+ (begin
+ (dict-update! dto dict key updater fail success)
+ dict)))
(define (dict-filter* dto pred dictionary)
- (if (dict-mutable? dto dictionary)
- (dict-filter! dto pred dictionary)
- (dict-filter dto pred dictionary)))
+ (if (dict-pure? dto dictionary)
+ (dict-filter dto pred dictionary)
+ (begin
+ (dict-filter! dto pred dictionary)
+ dictionary)))
(define (dict-replace* dto dict key val)
- (if (dict-mutable? dto dict)
- (dict-replace! dto dict key val)
- (dict-replace dto dict key val)))
+ (if (dict-pure? dto dict)
+ (dict-replace dto dict key val)
+ (begin
+ (dict-replace! dto dict key val)
+ dict)))
(define (default-dict-empty? dto dictionary)
(= 0 (dict-size dto dictionary)))
@@ -85,7 +100,7 @@
(error "mismatch of key / values argument list" objs))
(else (let* ((key (car objs))
(value (cadr objs))
- (new-d (dict-find-update* dto dictionary key
+ (new-d (dict-find-update*/dict dto dictionary key
(lambda (insert ignore)
(insert value))
(lambda (key old-value update delete)
@@ -108,7 +123,7 @@
(cond
((null? keylist) d)
(else (let* ((key (car keylist))
- (new-d (dict-find-update* dto d key
+ (new-d (dict-find-update*/dict dto d key
(lambda (_ ignore)
(ignore))
(lambda (key old-value _ delete)
@@ -124,12 +139,19 @@
(update key value))))
(define (default-dict-intern dto dictionary key failure)
+ (define pure (dict-pure? dto dictionary))
(dict-find-update* dto dictionary key
(lambda (insert _)
(let ((value (failure)))
- (values (insert value) value)))
+ (if pure
+ (values (insert value) value)
+ (begin
+ (insert value)
+ value))))
(lambda (key value update _)
- (values dictionary value))))
+ (if pure
+ (values dictionary value)
+ value))))
(define (default-dict-update dto dictionary key updater failure success)
(dict-find-update* dto dictionary key
@@ -151,23 +173,16 @@
(lambda (key value)
(define new-dict
(dict-delete-all* dto dictionary (list key)))
- (cont new-dict key value))
+ (if (dict-pure? dto dictionary)
+ (cont new-dict key value)
+ (cont key value)))
dictionary))))
(define empty? (dict-empty? dto dictionary))
(if empty?
(error "popped empty dictionary")
(do-pop)))
- (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 dto dict key))))
- (loop (cdr keys)
- (dict-replace* dto dict key val))))))
+ (define default-dict-map (not-implemented "dict-map"))
(define (default-dict-filter dto pred dictionary)
(define keys (dict-keys dto dictionary))
@@ -267,92 +282,111 @@
(define default-dict-comparator (not-implemented "dict-comparator"))
- (define default-dict-for-each (not-implemented "dict-for-each"))
-
- (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< dto proc dict key)
- (define cmp (dict-comparator dto dict))
- (define (pred k)
- (<? cmp k key))
- (default-dict-for-each/filtered dto pred proc 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 dto pred proc dict))
-
- (define (default-dict-for-each> dto proc dict key)
+ (define (default-dict-for-each dto proc dict start end)
+ (define (any . _) #t)
(define cmp (dict-comparator dto dict))
- (define (pred k)
- (>? cmp k key))
- (default-dict-for-each/filtered dto pred proc 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 dto pred proc 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 dto pred proc dict))
-
- (define (default-dict-for-each-in-closed-interval dto proc dict key1 key2)
+ (define lower
+ (if start
+ (lambda (el) (>=? cmp el start))
+ any))
+ (define upper
+ (if end
+ (lambda (el) (<=? cmp el end))
+ any))
+ (define (accept el)
+ (and (upper el) (lower el)))
+ (define map-proc
+ (if (dict-pure? dto dict)
+ dict-map
+ dict-map!))
+
+ (map-proc
+ dto
+ (lambda (key value)
+ (when (accept key)
+ (proc key value))
+ value)
+ dict))
+
+ (define (default-dict->generator dto dict start end)
+
+ (define (any . _) #t)
(define cmp (dict-comparator dto dict))
- (define (pred k)
- (<=? cmp key1 k key2))
- (default-dict-for-each/filtered dto pred proc 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 dto pred proc 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 dto pred proc dict))
-
- (define (default-make-dict-generator dto dict)
- (define-values (keys vals)
- (dict-entries dto dict))
+ (define lower
+ (if start
+ (lambda (el) (>=? cmp el start))
+ any))
+ (define upper
+ (if end
+ (lambda (el) (<=? cmp el end))
+ any))
+ (define (accept el)
+ (and (upper el) (lower el)))
+
+ ;; proc that takes yield value and yield continuation when yield is called
+ ;; shouldn't return
+ (define yield-handler #f)
+
+ (define (yield value)
+ (when (or (eof-object? value)
+ (accept (car value)))
+ (call/cc (lambda (yield-cont)
+ (yield-handler value yield-cont))) ))
+
+ (define (generate)
+ (dict-for-each dto
+ (lambda (key value)
+ (yield (cons key value)))
+ dict)
+ (yield (eof-object)))
+
+ ;; continuation at the point of last yield
+ (define yield-cont #f)
+
+ ;; check if eof return was seen; if yes, keep returning eof
+ ;; for further invocations
+ (define eof #f)
+
+ (define (get-next-value exit)
+ (set! yield-handler
+ (lambda (value new-yield-cont)
+ (set! yield-cont new-yield-cont)
+ (when (eof-object? value)
+ (set! eof #t)
+ ;; unset continuation reference to allow
+ ;; gc clean everything up
+ (set! yield-cont #f))
+ (exit value)))
+
+ (cond
+ ;; eof seen -- keep returning eof
+ (eof (eof-object))
+ ;; no yield called yet -- start the generator
+ ((not yield-cont) (generate))
+ ;; continue from last yield position
+ (else (yield-cont #t))))
+
(lambda ()
- (if (null? keys)
- (eof-object)
- (let ((key (car keys))
- (value (car vals)))
- (set! keys (cdr keys))
- (set! vals (cdr vals))
- (cons key value)))))
+ (call/cc get-next-value)))
(define (default-dict-accumulator dto dict acc-proc)
+ (define pure (dict-pure? dto dict))
(lambda (arg)
(if (eof-object? arg)
dict
- (set! dict (acc-proc dto dict (car arg) (cdr arg))))))
+ (if pure
+ (set! dict (acc-proc dto dict (car arg) (cdr arg)))
+ (acc-proc dto dict (car arg) (cdr arg))))))
(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)))
+ (if (dict-pure? dto dict)
+ (default-dict-accumulator dto dict dict-set)
+ (default-dict-accumulator dto dict dict-set!)))
(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)))
+ (if (dict-pure? dto dict)
+ (default-dict-accumulator dto dict dict-adjoin)
+ (default-dict-accumulator dto dict dict-adjoin!)))
(let ()
(define null-dto (make-dto-private (make-vector dict-procedures-count #f)))
@@ -363,7 +397,7 @@
dict-empty?-id default-dict-empty?
dict-contains?-id default-dict-contains?
dict=?-id default-dict=?
- dict-mutable?-id default-dict-mutable?
+ dict-pure?-id default-dict-pure?
dict-ref-id default-dict-ref
dict-ref/default-id default-dict-ref/default
dict-set-id default-dict-set
@@ -392,17 +426,9 @@
dict-comparator-id default-dict-comparator
dict-for-each-id default-dict-for-each
- dict-for-each<-id default-dict-for-each<
- dict-for-each<=-id default-dict-for-each<=
- dict-for-each>-id default-dict-for-each>
- dict-for-each>=-id default-dict-for-each>=
- dict-for-each-in-open-interval-id default-dict-for-each-in-open-interval
- dict-for-each-in-closed-interval-id default-dict-for-each-in-closed-interval
- dict-for-each-in-open-closed-interval-id default-dict-for-each-in-open-closed-interval
- dict-for-each-in-closed-open-interval-id default-dict-for-each-in-closed-open-interval
;; generator procedures
- make-dict-generator-id default-make-dict-generator
+ dict->generator-id default-dict->generator
dict-set-accumulator-id default-dict-set-accumulator
dict-adjoin-accumulator-id default-dict-adjoin-accumulator))
diff --git a/srfi/externals.scm b/srfi/externals.scm
index ce24b19..d08f4a4 100644
--- a/srfi/externals.scm
+++ b/srfi/externals.scm
@@ -35,11 +35,11 @@
(begin
(define (proc-mutable dto dict . args)
(assume (dto? dto))
- (assume ((dto-ref-stx dto dict-mutable?-id) dto dict) index)
+ (assume (not ((dto-ref-stx dto dict-pure?-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)
+ (assume ((dto-ref-stx dto dict-pure?-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)
@@ -51,17 +51,17 @@
(begin
(define (proc-mutable dto proc dict)
(assume (dto? dto))
- (assume ((dto-ref-stx dto dict-mutable?-id) dto dict) index)
+ (assume (not ((dto-ref-stx dto dict-pure?-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)
+ (assume ((dto-ref-stx dto dict-pure?-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)
(define/dict-proc dict-contains? dict-contains?-id)
-(define/dict-proc dict-mutable? dict-mutable?-id)
+(define/dict-proc dict-pure? dict-pure?-id)
(define/dict-proc dict=? dict=?-id)
(define dict-ref
@@ -98,7 +98,7 @@
((dto dict key updater failure success)
(assume (dto? dto))
- (assume (not ((dto-ref-stx dto dict-mutable?-id) dto dict)))
+ (assume ((dto-ref-stx dto dict-pure?-id) dto dict))
((dto-ref-stx dto dict-update-id) dto dict key updater failure success))))
(define dict-update!
@@ -113,7 +113,7 @@
((dto dict key updater failure success)
(assume (dto? dto))
- (assume ((dto-ref-stx dto dict-mutable?-id) dto dict))
+ (assume (not ((dto-ref-stx dto dict-pure?-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)
@@ -133,18 +133,21 @@
(define/dict-proc dict-map->list dict-map->list-id)
(define/dict-proc dict->alist dict->alist-id)
(define/dict-proc dict-comparator dict-comparator-id)
-(define/dict-proc dict-for-each dict-for-each-id)
-(define/dict-proc dict-for-each< dict-for-each<-id)
-(define/dict-proc dict-for-each<= dict-for-each<=-id)
-(define/dict-proc dict-for-each> dict-for-each>-id)
-(define/dict-proc dict-for-each>= dict-for-each>=-id)
-(define/dict-proc dict-for-each-in-open-interval dict-for-each-in-open-interval-id)
-(define/dict-proc dict-for-each-in-closed-interval dict-for-each-in-closed-interval-id)
-(define/dict-proc dict-for-each-in-open-closed-interval dict-for-each-in-open-closed-interval-id)
-(define/dict-proc dict-for-each-in-closed-open-interval dict-for-each-in-closed-open-interval-id)
-(define/dict-proc make-dict-generator make-dict-generator-id)
-(define/dict-proc dict-set-accumulator dict-set-accumulator-id)
-(define/dict-proc dict-adjoin-accumulator dict-adjoin-accumulator-id)
+
+(define dict-for-each
+ (case-lambda
+ ((dto proc dict) (dict-for-each dto proc dict #f #f))
+ ((dto proc dict start) (dict-for-each dto proc dict start #f))
+ ((dto proc dict start end) ((dto-ref-stx dto dict-for-each-id) dto proc dict start end))))
+
+(define dict->generator
+ (case-lambda
+ ((dto dict) (dict->generator dto dict #f #f))
+ ((dto dict start) (dict->generator dto dict start #f))
+ ((dto dict start end) ((dto-ref-stx dto dict->generator-id) dto dict start end))))
+
+(define/dict-proc-pair dict-set-accumulator dict-set!-accumulator dict-set-accumulator-id)
+(define/dict-proc-pair dict-adjoin-accumulator dict-adjoin!-accumulator dict-adjoin-accumulator-id)
(define (dto-ref dto procindex)
(dto-ref-stx dto procindex))
diff --git a/srfi/indexes.scm b/srfi/indexes.scm
index 2121558..f6a178f 100644
--- a/srfi/indexes.scm
+++ b/srfi/indexes.scm
@@ -9,7 +9,7 @@
(define dict-empty?-id (proc-id-inc))
(define dict-contains?-id (proc-id-inc))
(define dict=?-id (proc-id-inc))
-(define dict-mutable?-id (proc-id-inc))
+(define dict-pure?-id (proc-id-inc))
(define dict-ref-id (proc-id-inc))
(define dict-ref/default-id (proc-id-inc))
(define dict-set-id (proc-id-inc))
@@ -37,15 +37,7 @@
(define dict->alist-id (proc-id-inc))
(define dict-comparator-id (proc-id-inc))
(define dict-for-each-id (proc-id-inc))
-(define dict-for-each<-id (proc-id-inc))
-(define dict-for-each<=-id (proc-id-inc))
-(define dict-for-each>-id (proc-id-inc))
-(define dict-for-each>=-id (proc-id-inc))
-(define dict-for-each-in-open-interval-id (proc-id-inc))
-(define dict-for-each-in-closed-interval-id (proc-id-inc))
-(define dict-for-each-in-open-closed-interval-id (proc-id-inc))
-(define dict-for-each-in-closed-open-interval-id (proc-id-inc))
-(define make-dict-generator-id (proc-id-inc))
+(define dict->generator-id (proc-id-inc))
(define dict-set-accumulator-id (proc-id-inc))
(define dict-adjoin-accumulator-id (proc-id-inc))
(define dict-procedures-count (proc-id-inc)) ;; only used for tracking backing vector size
diff --git a/srfi/srfi-125-impl.scm b/srfi/srfi-125-impl.scm
index 1d5cf8e..736a27c 100644
--- a/srfi/srfi-125-impl.scm
+++ b/srfi/srfi-125-impl.scm
@@ -1,100 +1,67 @@
(define hash-table-dto
(let ()
- (define-syntax guard-immutable
- (syntax-rules ()
- ((_ table body ... final-expr)
- (if (t125-hash-table-mutable? table)
- (let ()
- body ...
- final-expr)
- (let ((table (t125-hash-table-copy table #t)))
- body ...
- (let ((table (t125-hash-table-copy table #f)))
- final-expr))))))
-
- (define (t125-hash-table-mutable?* dto table)
- (t125-hash-table-mutable? table))
+ (define (t125-hash-table-pure?* dto table)
+ #f)
(define (t125-hash-table-set* dto table . obj)
- (guard-immutable table
- (apply t125-hash-table-set! (cons table obj))
- table))
+ (apply t125-hash-table-set! (cons table obj)))
(define (t125-hash-table-update* dto table key updater fail success)
- (guard-immutable table
- (t125-hash-table-update! table key updater fail success)
- table))
+ (t125-hash-table-update! table key updater fail success))
(define (t125-hash-table-update/default* dto table key proc default)
- (guard-immutable table
- (t125-hash-table-update!/default table key proc default)
- table))
+ (t125-hash-table-update!/default table key proc default))
(define (t125-hash-table-intern* dto table key failure)
- (guard-immutable table
- (define val (t125-hash-table-intern! table key failure))
- (values table val)))
+ (t125-hash-table-intern! table key failure))
(define (t125-hash-table-pop* dto table)
(if (t125-hash-table-empty? table)
(error "popped empty dictionary")
- (guard-immutable table
- (define-values
- (key value)
- (t125-hash-table-pop! table))
- (values table key value))))
+ (t125-hash-table-pop! table)))
(define (t125-hash-table-delete-all* dto table keys)
- (guard-immutable table
- (for-each
+ (for-each
(lambda (key)
(t125-hash-table-delete! table key))
- keys)
- table))
+ keys))
(define (t125-hash-table-map* dto proc table)
- (guard-immutable table
- (t125-hash-table-map! proc table)
- table))
+ (t125-hash-table-map! proc table))
(define (t125-hash-table-filter* dto proc table)
- (guard-immutable table
- (t125-hash-table-prune!
+ (t125-hash-table-prune!
(lambda (key value)
(not (proc key value)))
- table)
- table))
+ table))
(define (t125-hash-table-remove* dto proc table)
- (guard-immutable table
- (t125-hash-table-prune! proc table)
- table))
+ (t125-hash-table-prune! proc table))
(define (t125-hash-table-find-update* dto table key fail success)
- (define (handle-success value)
+ ;; instead of running immediately,
+ ;; add an indirection through thunk
+ ;; to guarantee call in tail position
+ (define (make-success-thunk value)
(define (update new-key new-value)
- (guard-immutable table
- (unless (eq? new-key key)
- (t125-hash-table-delete! table key))
- (t125-hash-table-set! table new-key new-value)
- table))
+ (unless (eq? new-key key)
+ (t125-hash-table-delete! table key))
+ (t125-hash-table-set! table new-key new-value))
(define (remove)
- (guard-immutable table
- (t125-hash-table-delete! table key)
- table))
- (success key value update remove))
- (define (handle-fail)
+ (t125-hash-table-delete! table key))
+ (lambda ()
+ (success key value update remove) ))
+ (define (make-failure-thunk)
(define (ignore)
table)
(define (insert value)
- (guard-immutable table
- (t125-hash-table-set! table key value)
- table))
- (fail insert ignore))
+ (t125-hash-table-set! table key value))
+ (lambda ()
+ (fail insert ignore)))
- (define default (cons #f #f))
- (t125-hash-table-ref table key handle-fail handle-success))
+ (define thunk (t125-hash-table-ref table key make-failure-thunk make-success-thunk))
+ (thunk))
(define (t125-hash-table-comparator* dto table)
(make-comparator (lambda args #t)
@@ -108,9 +75,6 @@
(define (t125-hash-table-size* dto table)
(t125-hash-table-size table))
- (define (t125-hash-table-for-each* dto proc table)
- (t125-hash-table-for-each proc table))
-
(define (t125-hash-table-keys* dto table)
(t125-hash-table-keys table))
@@ -146,7 +110,7 @@
(make-dto
dictionary?-id t125-hash-table?*
- dict-mutable?-id t125-hash-table-mutable?*
+ dict-pure?-id t125-hash-table-pure?*
dict-empty?-id t125-hash-table-empty?*
dict-contains?-id t125-hash-table-contains?*
dict-ref-id t125-hash-table-ref*
@@ -162,7 +126,6 @@
dict-remove-id t125-hash-table-remove*
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*
dict-values-id t125-hash-table-values*
dict-entries-id t125-hash-table-entries*
diff --git a/srfi/srfi-126-impl.scm b/srfi/srfi-126-impl.scm
index e1f62f1..b4c9845 100644
--- a/srfi/srfi-126-impl.scm
+++ b/srfi/srfi-126-impl.scm
@@ -1,21 +1,12 @@
(define srfi-126-dto
(let ()
- (define-syntax guard-immutable
- (syntax-rules ()
- ((_ table body ... final-expr)
- (if (t126-hashtable-mutable? table)
- (let ()
- body ...
- final-expr)
- (let ((table (t126-hashtable-copy table #t)))
- body ...
- (let ((table (t126-hashtable-copy table #f)))
- final-expr))))))
-
(define (prep-dto-arg proc)
(lambda (dto . args)
(apply proc args)))
+
+ (define (t126-hashtable-pure?* dto table)
+ #f)
(define (t126-hashtable-ref* dto table key fail success)
(define-values (value found?) (t126-hashtable-lookup table key))
@@ -27,79 +18,55 @@
(t126-hashtable-ref table key default))
(define (t126-hashtable-set* dto table . obj)
- (guard-immutable table
- (let loop ((obj obj))
+ (let loop ((obj obj))
(if (null? obj)
#t
(begin
(t126-hashtable-set! table (car obj) (cadr obj))
- (loop (cddr obj)))))
- table))
+ (loop (cddr obj))))))
(define (t126-hashtable-delete-all* dto table keys)
- (guard-immutable table
- (for-each
+ (for-each
(lambda (key)
(t126-hashtable-delete! table key))
- keys)
- table))
+ keys))
(define (t126-hashtable-intern* dto table key default)
- (guard-immutable table
- (define val (t126-hashtable-intern! table key default))
- (values table val)))
+ (t126-hashtable-intern! table key default))
(define (t126-hashtable-update/default* dto table key updater default)
- (guard-immutable table
- (t126-hashtable-update! table key updater default)
- table))
+ (t126-hashtable-update! table key updater default))
(define (t126-hashtable-pop* dto table)
(if (t126-hashtable-empty? table)
(error "popped empty dictionary")
- (guard-immutable table
- (define-values
- (key value)
- (t126-hashtable-pop! table))
- (values table key value))))
+ (t126-hashtable-pop! table)))
(define (t126-hashtable-update-all* dto proc table)
- (guard-immutable table
- (t126-hashtable-update-all! table proc)
- table))
+ (t126-hashtable-update-all! table proc))
(define (t126-hashtable-filter* dto proc table)
- (guard-immutable table
- (t126-hashtable-prune! table
+ (t126-hashtable-prune! table
(lambda (key value)
- (not (proc key value))))
- table))
+ (not (proc key value)))))
(define (t126-hashtable-remove* dto proc table)
- (guard-immutable table
- (t126-hashtable-prune! table proc)
- table))
+ (t126-hashtable-prune! table proc))
(define (t126-hashtable-find-update* dto table key fail success)
(define (handle-success value)
(define (update new-key new-value)
- (guard-immutable table
- (unless (eq? new-key key)
+ (unless (eq? new-key key)
(t126-hashtable-delete! table key))
- (t126-hashtable-set! table new-key new-value)
- table))
+ (t126-hashtable-set! table new-key new-value))
(define (remove)
- (guard-immutable table
- (t126-hashtable-delete! table key)
- table))
+ (t126-hashtable-delete! table key))
(success key value update remove))
(define (handle-fail)
(define (ignore)
table)
(define (insert value)
- (guard-immutable table
- (t126-hashtable-set! table key value)
- table))
+ (t126-hashtable-set! table key value))
(fail insert ignore))
(define default (cons #f #f))
@@ -108,10 +75,6 @@
(handle-fail)
(handle-success found)))
- (define (t126-hashtable-for-each* dto proc table)
- (t126-hashtable-walk table proc)
- table)
-
(define (t126-hashtable-map->lset* dto proc table)
(t126-hashtable-map->lset table proc))
@@ -134,7 +97,7 @@
(make-dto
dictionary?-id (prep-dto-arg t126-hashtable?)
- dict-mutable?-id (prep-dto-arg t126-hashtable-mutable?)
+ dict-pure?-id t126-hashtable-pure?*
dict-empty?-id (prep-dto-arg t126-hashtable-empty?)
dict-contains?-id (prep-dto-arg t126-hashtable-contains?)
dict-ref-id t126-hashtable-ref*
@@ -149,7 +112,6 @@
dict-remove-id t126-hashtable-remove*
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*
dict-entries-id t126-hashtable-entries*
diff --git a/srfi/srfi-146-hash-impl.scm b/srfi/srfi-146-hash-impl.scm
index 822fe7f..609fce9 100644
--- a/srfi/srfi-146-hash-impl.scm
+++ b/srfi/srfi-146-hash-impl.scm
@@ -4,6 +4,11 @@
(define (prep-dto-arg proc)
(lambda (dto . args)
(apply proc args)))
+
+ (define (hashmap-map* dto proc dict)
+ (hashmap-map (lambda (key value)
+ (values key (proc key value)))
+ (dict-comparator dto dict) dict))
(define (hashmap-find-update* dto dict key failure success)
(call/cc
@@ -38,7 +43,8 @@
(make-dto
dictionary?-id (prep-dto-arg hashmap?)
- dict-mutable?-id (lambda _ #f)
+ dict-pure?-id (lambda _ #t)
+ dict-map-id hashmap-map*
dict-empty?-id (prep-dto-arg hashmap-empty?)
dict-contains?-id (prep-dto-arg hashmap-contains?)
dict-ref-id (prep-dto-arg hashmap-ref)
@@ -56,7 +62,6 @@
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)
diff --git a/srfi/srfi-146-impl.scm b/srfi/srfi-146-impl.scm
index ad6b629..c6280ba 100644
--- a/srfi/srfi-146-impl.scm
+++ b/srfi/srfi-146-impl.scm
@@ -4,6 +4,11 @@
(define (prep-dto-arg proc)
(lambda (dto . args)
(apply proc args)))
+
+ (define (mapping-map* dto proc dict)
+ (mapping-map (lambda (key value)
+ (values key (proc key value)))
+ (dict-comparator dto dict) dict))
(define (mapping-find-update* dto dict key failure success)
(call/cc
@@ -38,7 +43,8 @@
(make-dto
dictionary?-id (prep-dto-arg mapping?)
- dict-mutable?-id (lambda _ #f)
+ dict-pure?-id (lambda _ #t)
+ dict-map-id mapping-map*
dict-empty?-id (prep-dto-arg mapping-empty?)
dict-contains?-id (prep-dto-arg mapping-contains?)
dict-ref-id (prep-dto-arg mapping-ref)
@@ -56,7 +62,6 @@
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)
diff --git a/srfi/srfi-69-impl.scm b/srfi/srfi-69-impl.scm
index c61036e..dfa9b76 100644
--- a/srfi/srfi-69-impl.scm
+++ b/srfi/srfi-69-impl.scm
@@ -5,8 +5,8 @@
(lambda (dto . args)
(apply proc args)))
- (define (t69-hash-table-mutable?* dto table)
- #t)
+ (define (t69-hash-table-pure?* dto table)
+ #f)
(define (t69-hash-table-ref* dto table key fail success)
(define default (cons #f #f))
@@ -34,9 +34,6 @@
keys)
table)
- (define (t69-hash-table-foreach* dto proc table)
- (t69-hash-table-walk table proc))
-
(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))))
@@ -86,7 +83,7 @@
(make-dto
dictionary?-id (prep-dto-arg t69-hash-table?)
- dict-mutable?-id t69-hash-table-mutable?*
+ dict-pure?-id t69-hash-table-pure?*
dict-ref-id t69-hash-table-ref*
dict-ref/default-id (prep-dto-arg t69-hash-table-ref/default)
dict-set-id t69-hash-table-set!*
@@ -98,7 +95,6 @@
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-dto-arg t69-hash-table->alist)
dict-find-update-id t69-hash-table-find-update!*