summaryrefslogtreecommitdiffstats
path: root/srfi/srfi-126-impl.scm
diff options
context:
space:
mode:
authorGravatar Arvydas Silanskas 2021-10-17 12:09:08 +0300
committerGravatar Arvydas Silanskas 2021-10-17 12:09:08 +0300
commit1e501c16b620c976a9b2d85ba5ad82b5e83ae0da (patch)
tree000f4e1c767113245478e5485f2bf4cc05a6d3e0 /srfi/srfi-126-impl.scm
parentwork (diff)
work
Diffstat (limited to 'srfi/srfi-126-impl.scm')
-rw-r--r--srfi/srfi-126-impl.scm157
1 files changed, 81 insertions, 76 deletions
diff --git a/srfi/srfi-126-impl.scm b/srfi/srfi-126-impl.scm
index 43dd9b5..d5de302 100644
--- a/srfi/srfi-126-impl.scm
+++ b/srfi/srfi-126-impl.scm
@@ -1,14 +1,22 @@
(define srfi-126-dtd
(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-dtd-arg proc)
(lambda (dtd . args)
(apply proc args)))
-
- (define (t126-make-hashtable* dtd comparator)
- (t126-make-hashtable (comparator-hash-function comparator)
- (comparator-equality-predicate comparator)))
-
+
(define (t126-hashtable-ref* dtd table key fail success)
(define-values (value found?) (t126-hashtable-lookup table key))
(if found?
@@ -18,73 +26,80 @@
(define (t126-hashtable-ref/default* dtd table key default)
(t126-hashtable-ref table key default))
- (define (t126-hashtable-set!* dtd table . obj)
- (let loop ((obj obj))
- (if (null? obj)
- table
- (begin
- (t126-hashtable-set! table (car obj) (cadr obj))
- (loop (cddr obj))))))
-
- (define (t126-hashtable-delete-all!* dtd table keys)
- (for-each
- (lambda (key)
- (t126-hashtable-delete! table key))
- keys)
- table)
+ (define (t126-hashtable-set* dtd table . obj)
+ (guard-immutable table
+ (let loop ((obj obj))
+ (if (null? obj)
+ #t
+ (begin
+ (t126-hashtable-set! table (car obj) (cadr obj))
+ (loop (cddr obj)))))
+ table))
+
+ (define (t126-hashtable-delete-all* dtd table keys)
+ (guard-immutable table
+ (for-each
+ (lambda (key)
+ (t126-hashtable-delete! table key))
+ keys)
+ table))
- (define (t126-hashtable-intern!* dtd table key default)
- (define val (t126-hashtable-intern! table key default))
- (values table val))
+ (define (t126-hashtable-intern* dtd 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)
- (t126-hashtable-update! table key updater default)
- table)
+ (define (t126-hashtable-update/default* dtd 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* dtd table)
(if (t126-hashtable-empty? table)
(error "popped empty dictionary")
- (call-with-values
- (lambda () (t126-hashtable-pop! table))
- (lambda (key value) (values table key value)))))
-
- (define (t126-hashtable-update-all!* dtd proc table)
- (t126-hashtable-update-all! table proc)
- table)
+ (guard-immutable table
+ (define-values
+ (key value)
+ (t126-hashtable-pop! table))
+ (values table key value))))
- (define (t126-hashtable-filter!* dtd proc table)
- (t126-hashtable-prune! table
- (lambda (key value)
- (not (proc key value))))
- table)
+ (define (t126-hashtable-update-all* dtd proc table)
+ (guard-immutable table
+ (t126-hashtable-update-all! table proc)
+ table))
(define (t126-hashtable-filter* dtd proc table)
- (dict-filter! dtd proc (dict-copy dtd table)))
-
- (define (t126-hashtable-remove!* dtd proc table)
- (t126-hashtable-prune! table proc)
- table)
+ (guard-immutable table
+ (t126-hashtable-prune! table
+ (lambda (key value)
+ (not (proc key value))))
+ table))
(define (t126-hashtable-remove* dtd proc table)
- (dict-remove! dtd proc (dict-copy dtd table)))
+ (guard-immutable table
+ (t126-hashtable-prune! table proc)
+ table))
- (define (t126-hashtable-search!* dtd table key fail success)
+ (define (t126-hashtable-alter* dtd table key fail success)
(define (handle-success value)
- (define (update new-key new-value obj)
- (unless (eq? new-key key)
- (t126-hashtable-delete! table key))
- (t126-hashtable-set! table new-key new-value)
- (values table obj))
- (define (remove obj)
- (t126-hashtable-delete! table key)
- (values table obj))
+ (define (update new-key new-value)
+ (guard-immutable table
+ (unless (eq? new-key key)
+ (t126-hashtable-delete! table key))
+ (t126-hashtable-set! table new-key new-value)
+ table))
+ (define (remove)
+ (guard-immutable table
+ (t126-hashtable-delete! table key)
+ table))
(success key value update remove))
(define (handle-fail)
- (define (ignore obj)
- (values table obj))
- (define (insert value obj)
- (t126-hashtable-set! table key value)
- (values table obj))
+ (define (ignore)
+ table)
+ (define (insert value)
+ (guard-immutable table
+ (t126-hashtable-set! table key value)
+ table))
(fail insert ignore))
(define default (cons #f #f))
@@ -93,9 +108,6 @@
(handle-fail)
(handle-success found)))
- (define (t126-hashtable-search* dtd table key fail success)
- (dict-search! dtd (dict-copy dtd table) key fail success))
-
(define (t126-hashtable-for-each* dtd proc table)
(t126-hashtable-walk table proc)
table)
@@ -117,36 +129,29 @@
(vector->list keys)
(vector->list vals)))))
- (define (t126-hashtable-copy* dtd table)
- (t126-hashtable-copy table #t))
-
(define (t126-hashtable-comparator* dtd table)
#f)
(make-dtd
- make-dictionary-id t126-make-hashtable*
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?)
dict-ref-id t126-hashtable-ref*
dict-ref/default-id t126-hashtable-ref/default*
- dict-set!-id t126-hashtable-set!*
- dict-delete-all!-id t126-hashtable-delete-all!*
- dict-intern!-id t126-hashtable-intern!*
- dict-update/default!-id t126-hashtable-update/default!*
- dict-pop!-id t126-hashtable-pop!*
- dict-map!-id t126-hashtable-update-all!*
- dict-filter!-id t126-hashtable-filter!*
+ dict-set-id t126-hashtable-set*
+ dict-delete-all-id t126-hashtable-delete-all*
+ dict-intern-id t126-hashtable-intern*
+ dict-update/default-id t126-hashtable-update/default*
+ dict-pop-id t126-hashtable-pop*
+ dict-map-id t126-hashtable-update-all*
dict-filter-id t126-hashtable-filter*
- dict-remove!-id t126-hashtable-remove!*
dict-remove-id t126-hashtable-remove*
- dict-search!-id t126-hashtable-search!*
- dict-search-id t126-hashtable-search*
+ dict-alter-id t126-hashtable-alter*
dict-size-id (prep-dtd-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*
dict-map->list-id t126-hashtable-map->lset*
- dict-copy-id t126-hashtable-copy*
dict-comparator-id t126-hashtable-comparator*)))
td/> git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@35 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-08-06Added support for isochronous sending.Gravatar aeb 3-0/+35 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@34 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-07-05Added raw1394_reset_bus() call.Gravatar aeb 4-0/+23 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@33 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-06-22- Set library version info in configure.in, use in src/Makefile.am.Gravatar aeb 4-2/+16 - Enable compiler warnings. git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@32 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-06-15Update libtool version number.Gravatar aeb 2-2/+2 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@31 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-06-14Added copyright headers.Gravatar aeb 6-0/+54 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@30 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-06-11Added explicit AC_PROG_INSTALL call.Gravatar aeb 1-0/+1 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@29 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-06-09Fix size of error field.Gravatar aeb 1-2/+2 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@28 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-06-02Modified support for 32/64 bit environments, control struct fields have ↵Gravatar aeb 7-43/+28 fixed size now. git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@27 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-05-28Added support for environments with 64 bit kernel and 32 bit userland.Gravatar aeb 8-7/+45 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@26 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-04-27Fixed missing setting of ext code in raw1394_start_lock()Gravatar aeb 1-0/+1 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@25 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-04-15Fixed lock transaction to actually return response value.Gravatar aeb 3-5/+11 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@24 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-04-12Add userdata functions as news.Gravatar aeb 1-0/+4 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@23 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-04-05Add userdata functions.Gravatar aeb 3-0/+18 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@22 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-03-18Bump version number to 0.6.Gravatar aeb 3-5/+6 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@21 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-03-18Mention byte order change.Gravatar aeb 1-0/+2 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@20 53a565d1-3bb7-0310-b661-cf11e63c67ab 2000-03-18Mention SourceForge home.Gravatar aeb 1-1/+5 git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@19 53a565d1-3bb7-0310-b661-cf11e63c67ab