diff options
| author | 2021-08-19 01:33:46 +0300 | |
|---|---|---|
| committer | 2021-08-19 01:33:46 +0300 | |
| commit | 9d85b17d285fdda422b2bce0a6272b0ff6b2cf29 (patch) | |
| tree | c16b9a9882307bfd83ade9956be77e8b3a6780cc | |
| parent | update spec; fix default copy (diff) | |
remove old files
| -rw-r--r-- | TODO.md | 5 | ||||
| -rw-r--r-- | alist-impl.scm | 96 | ||||
| -rw-r--r-- | dictionaries-impl.scm | 34 | ||||
| -rw-r--r-- | dictionaries.sld | 65 | ||||
| -rw-r--r-- | externals.scm | 158 | ||||
| -rw-r--r-- | indexes.scm | 70 | ||||
| -rw-r--r-- | internals.scm | 242 | ||||
| -rw-r--r-- | makefile | 21 | ||||
| -rw-r--r-- | plist-impl.scm | 93 | ||||
| -rw-r--r-- | srfi-125-impl.scm | 93 | ||||
| -rw-r--r-- | srfi-126-impl.scm | 122 | ||||
| -rw-r--r-- | srfi-69-impl.scm | 88 |
12 files changed, 7 insertions, 1080 deletions
@@ -0,0 +1,5 @@ +# Document Title + +* TODO bits in test +* Debug why not providing dict-filter in eg srfi69 implementation fails tests + diff --git a/alist-impl.scm b/alist-impl.scm deleted file mode 100644 index 9ce3c35..0000000 --- a/alist-impl.scm +++ /dev/null @@ -1,96 +0,0 @@ -(define (make-alist-dtd key=) - - (define (alist? l) - (and (list? l) - (or (null? l) - (pair? (car l))))) - - (define (alist-map! proc alist) - (map - (lambda (e) - (define key (car e)) - (define value (cdr e)) - (cons key (proc key value))) - alist)) - - (define (alist-filter pred alist) - (filter - (lambda (e) - (pred (car e) (cdr e))) - alist)) - - (define (alist-filter! pred alist) - (filter! - (lambda (e) - (pred (car e) (cdr e))) - alist)) - - (define (alist-delete dtd key alist) - (filter - (lambda (entry) - (not (key= (car entry) key))) - alist)) - - (define (alist-delete! dtd key alist) - (filter! - (lambda (entry) - (not (key= (car entry) key))) - alist)) - - (define (alist-search* dtd alist-delete-proc alist key failure success) - (define (handle-success pair) - (define old-key (car pair)) - (define old-value (cdr pair)) - (define (update new-key new-value obj) - (cond - ((and (eq? old-key - new-key) - (eq? old-value - new-value)) - (values alist obj)) - (else - (let ((new-list - (alist-cons - new-key new-value - (alist-delete-proc old-key alist)))) - (values new-list obj))))) - (define (remove obj) - (values (alist-delete old-key alist) obj)) - (success old-key old-value update remove)) - - (define (handle-failure) - (define (insert value obj) - (values (alist-cons key value alist) - obj)) - (define (ignore obj) - (values alist obj)) - (failure insert ignore)) - (cond - ((assoc key alist) => handle-success) - (else (handle-failure)))) - - (define (alist-search dtd alist key failure success) - (alist-search* dtd alist-delete alist key failure success)) - - (define (alist-search! dtd alist key failure success) - (alist-search* dtd alist-delete! alist key failure success)) - - (define (alist-size alist) - (length alist)) - - (define (alist-foreach proc alist) - (define (proc* e) - (proc (car e) (cdr e))) - (for-each proc* alist)) - - (define (alist->alist alist) - alist) - - (-dictionary! - 'dictionary? alist? - 'dict-map! alist-map! - 'dict-filter! alist-filter! - 'dict-search! alist-search! - 'dict-size alist-size - 'dict-for-each alist-foreach - 'dict->alist alist->alist)) diff --git a/dictionaries-impl.scm b/dictionaries-impl.scm deleted file mode 100644 index a5473f9..0000000 --- a/dictionaries-impl.scm +++ /dev/null @@ -1,34 +0,0 @@ -(include "indexes.scm") -(include "internals.scm") -(include "externals.scm") - -;; register -(let () - (include "alist-impl.scm") - (register-alist!)) - -(let () - (include "plist-impl.scm") - (register-plist!)) - -(cond-expand - ((library (srfi 126)) - (let () - (include "srfi-126-impl.scm") - (register-srfi-126!))) - (else)) - -(cond-expand - ((library (srfi 125)) - (let () - (include "srfi-125-impl.scm") - (register-srfi-125!))) - (else)) - -(cond-expand - ((and (library (srfi 69)) - (not (library (srfi 125)))) - (let () - (include "srfi-69-impl.scm") - (register-srfi-69!))) - (else)) diff --git a/dictionaries.sld b/dictionaries.sld deleted file mode 100644 index e6c9b8d..0000000 --- a/dictionaries.sld +++ /dev/null @@ -1,65 +0,0 @@ -(define-library - (dictionaries) - (import (scheme base) - (scheme case-lambda) - (srfi 1)) - - (cond-expand - (kawa (import (srfi 69 basic-hash-tables))) - (guile (import (srfi srfi-69))) - ((library (srfi 69)) (import (srfi 69))) - (else)) - - (cond-expand - (guile) - ((library (srfi 125)) (import (srfi 125))) - (else)) - - (cond-expand - (guile) - ((library (srfi 126)) (import (srfi 126))) - (else)) - - (export - - ;; predicates - dictionary? - dict-empty? - dict-contains? - - ;; lookup - dict-ref - dict-ref/default - - ;; mutation - dict-set! - dict-adjoin! - dict-delete! - dict-delete-all! - dict-replace! - dict-intern! - dict-update! - dict-update/default! - dict-pop! - dict-map! - dict-filter! - dict-remove! - dict-search! - - ;; whole dictionary - dict-size - dict-for-each - dict-count - dict-any - dict-every - dict-keys - dict-values - dict-entries - dict-fold - dict-map->list - dict->alist - - ;; registering dictionary types - register-dictionary!) - - (include "dictionaries-impl.scm")) diff --git a/externals.scm b/externals.scm deleted file mode 100644 index 1c5ffe8..0000000 --- a/externals.scm +++ /dev/null @@ -1,158 +0,0 @@ -(define registry '()) - -(define (lookup dictionary fail-on-notfound?) - (let loop ((r registry)) - (cond - ((null? r) (if fail-on-notfound? - (error "Not a recognized dictionary" dictionary) - #f)) - ((dcall d? (car r) dictionary) (car r)) - (else (loop (cdr r)))))) - -(define (make-internal-wrapper name proc) - (cond - ((or (equal? name 'dict-set!) - (equal? name 'dict-adjoin!) - (equal? name 'dict-delete!)) - (lambda (vec dict objs) - (apply proc (cons dict objs)))) - (else - (lambda (vec . args) - (apply proc args))))) - -(define (register-dictionary! . lst) - (define vec (vector-copy model-vec)) - (do ((lst lst (cddr lst))) - ((null? lst)) - (when (null? (cdr lst)) - (error "Uneven amount of arguments" lst)) - (let ((proc-name (car lst)) - (proc (cadr lst))) - (define index - (cond - ((assoc proc-name dname-map) => cdr) - (else (error "Unrecognized procedure name" proc-name)))) - (unless (procedure? proc) - (error "Not a procedure" proc)) - (vector-set! vec index (make-internal-wrapper proc-name proc)))) - (let loop ((reg registry)) - (define new-reg (reverse (cons vec (reverse reg)))) - (if (eq? reg registry) - (set! registry new-reg) - (loop registry)))) - - -;;; External (exported) procedure definitions -(define-syntax dispatch - (syntax-rules () - ((dispatch index dictionary args ...) - (let ((vec (lookup dictionary #t))) ; error if not found - ((vector-ref vec index) vec dictionary args ...))))) - -(define-syntax proc-dispatch - (syntax-rules () - ((dispatch index dictionary args ...) - (let ((vec (lookup dictionary #t))) ; error if not found - ((vector-ref vec index) vec args ...))))) - -(define (dictionary? obj) - (if (lookup obj #f) #t #f)) ; #f if not found - -(define (dict-empty? dictionary) - (dispatch dempty? dictionary)) - -(define (dict-contains? dictionary key) - (dispatch dcontains? dictionary key)) - -(define dict-ref - (case-lambda - ((dictionary key) - (dict-ref dictionary key error values)) - ((dictionary key failure) - (dict-ref dictionary key failure values)) - ((dictionary key failure success) - (dict-ref* dictionary key failure success)))) - -(define (dict-ref* dictionary key failure success) - (dispatch dref dictionary key failure success)) - -(define (dict-ref/default dictionary key default) - (dispatch dref/default dictionary key default)) - -(define (dict-set! dictionary . objs) - (dispatch dset! dictionary objs)) - -(define (dict-adjoin! dictionary . objs) - (dispatch dadjoin! dictionary objs)) - -(define (dict-delete! dictionary . keys) - (dispatch ddelete! dictionary keys)) - -(define (dict-delete-all! dictionary keylist) - (dispatch ddelete-all! dictionary keylist)) - -(define (dict-replace! dictionary key value) - (dispatch dreplace! dictionary key value)) - -(define (dict-intern! dictionary key failure) - (dispatch dintern! dictionary key failure)) - -(define dict-update! - (case-lambda - ((dictionary key updater) - (dict-update! dictionary key updater error values)) - ((dictionary key updater failure) - (dict-update! dictionary key updater failure values)) - ((dictionary key updater failure success) - (dispatch dupdate! dictionary key updater failure success)))) - -(define (dict-update/default! dictionary key updater default) - (dispatch dupdate/default! dictionary key updater default)) - -(define (dict-pop! dictionary) - (dispatch dpop! dictionary)) - -(define (dict-map! proc dictionary) - (proc-dispatch dmap! dictionary proc dictionary)) - -(define (dict-filter! pred dictionary) - (proc-dispatch dfilter! dictionary pred dictionary)) - -(define (dict-remove! pred dictionary) - (proc-dispatch dremove! dictionary pred dictionary)) - -(define (dict-search! dictionary key failure success) - (dispatch dsearch! dictionary key failure success)) - -(define (dict-size dictionary) - (dispatch dsize dictionary)) - -(define (dict-for-each proc dictionary) - (proc-dispatch dfor-each dictionary proc dictionary)) - -(define (dict-count pred dictionary) - (proc-dispatch dcount dictionary pred dictionary)) - -(define (dict-any pred dictionary) - (proc-dispatch dany dictionary pred dictionary)) - -(define (dict-every pred dictionary) - (proc-dispatch devery dictionary pred dictionary)) - -(define (dict-keys dictionary) - (dispatch dkeys dictionary)) - -(define (dict-values dictionary) - (dispatch dvalues dictionary)) - -(define (dict-entries dictionary) - (dispatch dentries dictionary)) - -(define (dict-fold proc knil dictionary) - (proc-dispatch dfold dictionary proc knil dictionary)) - -(define (dict-map->list proc dictionary) - (proc-dispatch dmap->list dictionary proc dictionary)) - -(define (dict->alist dictionary) - (dispatch d->alist dictionary)) diff --git a/indexes.scm b/indexes.scm deleted file mode 100644 index a5f5568..0000000 --- a/indexes.scm +++ /dev/null @@ -1,70 +0,0 @@ -;;;; Indexes into dictionary vectors -;;; Add more at the end for new dictionary methods -;;; Add an entry to model-vec as well - -(define d? 0) -(define dempty? 1) -(define dcontains? 2) -(define dref 3) -(define dref/default 4) -(define dset! 5) -(define dadjoin! 6) -(define ddelete! 7) -(define ddelete-all! 8) -(define dreplace! 9) -(define dintern! 10) -(define dupdate! 11) -(define dupdate/default! 12) -(define dpop! 13) -(define dmap! 14) -(define dfilter! 15) -(define dremove! 16) -(define dsearch! 17) -(define dsize 18) -(define dfor-each 19) -(define dcount 20) -(define dany 21) -(define devery 22) -(define dkeys 23) -(define dvalues 24) -(define dentries 25) -(define dfold 26) -(define dmap->list 27) -(define d->alist 28) - - -;;; Sample of a call to an internal procedure from another internal procedure: -;;; (dcall dref/default vec dict key default) - -;;; Maps names to indexes - -(define dname-map - `((dictionary? . ,d?) - (dict-empty? . ,dempty?) - (dict-contains? . ,dcontains?) - (dict-ref . ,dref) - (dict-ref/default . ,dref/default) - (dict-set! . ,dset!) - (dict-adjoin! . ,dadjoin!) - (dict-delete! . ,ddelete!) - (dict-delete-all! . ,ddelete-all!) - (dict-replace! . ,dreplace!) - (dict-intern! . ,dintern!) - (dict-update! . ,dupdate!) - (dict-update/default! . ,dupdate/default!) - (dict-pop! . ,dpop!) - (dict-map! . ,dmap!) - (dict-filter! . ,dfilter!) - (dict-remove! . ,dremove!) - (dict-search! . ,dsearch!) - (dict-size . ,dsize) - (dict-for-each . ,dfor-each) - (dict-count . ,dcount) - (dict-any . ,dany) - (dict-every . ,devery) - (dict-keys . ,dkeys) - (dict-values . ,dvalues) - (dict-entries . ,dentries) - (dict-fold . ,dfold) - (dict-map->list . ,dmap->list) - (dict->alist . ,d->alist))) diff --git a/internals.scm b/internals.scm deleted file mode 100644 index d47678b..0000000 --- a/internals.scm +++ /dev/null @@ -1,242 +0,0 @@ -;;;; Internal procedure definitions (all take a vec argument first) - -;;; Sample call of an internal procedure from another internal procedure: -;;; (dcall dref/default vec dictionary key default) - -;;; Notes on definitions: -;;; Vec argument is not used except to pass to dcalls -;;; External procedures with a rest argument use a list argument here -;;; External procedures with optional arguments are not optional here - -(define-syntax dcall - (syntax-rules () - ((dcall dproc vec dictionary arg ...) - ((vector-ref vec dproc) vec dictionary arg ...)))) - -(define (idictionary? vec obj) - (error "dictionary? method not defined")) - -(define (idict-empty? vec dictionary) - (= 0 (dcall dsize vec dictionary))) - -(define (idict-contains? vec dictionary key) - (dcall dref vec dictionary key - (lambda () #f) (lambda (x) #t))) - -(define (idict-ref vec dictionary key failure success) - (define-values - (new-dict result) - (dcall dsearch! vec dictionary key - (lambda (_ ignore) - (ignore (failure))) - (lambda (key value update _) - (update key value (success value))))) - result) - -(define (idict-ref/default vec dictionary key default) - (dcall dref vec dictionary key - (lambda () default) - (lambda (x) x))) - -;; private -(define (idict-set!* vec dictionary use-old? objs) - (let loop ((objs objs) - (dictionary dictionary)) - (cond - ((null? objs) - dictionary) - ((null? (cdr objs)) - (error "mismatch of key / values argument list" objs)) - (else (let*-values - (((key) (car objs)) - ((value) (cadr objs)) - ((new-d _) (dcall dsearch! vec dictionary key - (lambda (insert ignore) - (insert value #f)) - (lambda (key old-value update delete) - (update key (if use-old? old-value value) #f))))) - (loop (cddr objs) - new-d)))))) - -(define (idict-set! vec dictionary objs) - (idict-set!* vec dictionary #f objs)) - -(define (idict-adjoin! vec dictionary objs) - (idict-set!* vec dictionary #t objs)) - -(define (idict-delete! vec dictionary keys) - (dcall ddelete-all! vec dictionary keys)) - -(define (idict-delete-all! vec dictionary keylist) - (let loop ((keylist keylist) - (dictionary dictionary)) - (cond - ((null? keylist) dictionary) - (else (let*-values - (((key) (car keylist)) - ((new-d _) (dcall dsearch! vec dictionary key - (lambda (_ ignore) - (ignore #f)) - (lambda (key old-value _ delete) - (delete #f))))) - (loop (cdr keylist) - new-d)))))) - -(define (idict-replace! vec dictionary key value) - (define-values - (new-dict _) - (dcall dsearch! vec dictionary key - (lambda (_ ignore) - (ignore #f)) - (lambda (key old-value update _) - (update key value #f)))) - new-dict) - -(define (idict-intern! vec dictionary key failure) - (dcall dsearch! vec dictionary key - (lambda (insert _) - (let ((value (failure))) - (insert value value))) - (lambda (key value update _) - (update key value value)))) - -(define (idict-update! vec dictionary key updater failure success) - (define-values - (new-dict _) - (dcall dsearch! vec dictionary key - (lambda (insert ignore) - (insert (updater (failure)) #f)) - (lambda (key value update _) - (update key (updater (success value)) #f)))) - new-dict) - -(define (idict-update/default! vec dictionary key updater default) - (dcall dupdate! vec dictionary key updater - (lambda () default) - (lambda (x) x))) - -(define (idict-pop! vec dictionary) - (define (do-pop) - (call/cc - (lambda (cont) - (dcall dfor-each vec - (lambda (key value) - (define new-dict - (dcall ddelete! vec dictionary (list key))) - (cont new-dict key value)) - dictionary)))) - (define empty? (dcall dempty? vec dictionary)) - (if empty? - (error "popped empty dictionary") - (do-pop))) - -(define (idict-map! vec proc dictionary) - (error "dict-map method not defined")) - -(define (idict-filter! vec pred dictionary) - (error "dict-filter! method not defined")) - -(define (idict-remove! vec pred dictionary) - (dcall dfilter! vec (lambda (key value) (not (pred key value))) dictionary)) - -(define (idict-search! vec dictionary key failure success) - (error "dict-search! method not defined")) - -(define (idict-size vec dictionary) - (error "dict-size method not defined")) - -(define (idict-for-each vec proc dictionary) - (error "dict-for-each method not defined")) - -(define (idict-count vec pred dictionary) - (dcall dfold vec - (lambda (key value acc) - (if (pred key value) - (+ 1 acc) - acc)) - 0 - dictionary)) - -(define (idict-any vec pred dictionary) - (call/cc - (lambda (cont) - (dcall dfor-each vec - (lambda (key value) - (define ret (pred key value)) - (when ret - (cont ret))) - dictionary) - #f))) - -(define (idict-every vec pred dictionary) - (define last #t) - (call/cc - (lambda (cont) - (dcall dfor-each vec - (lambda (key value) - (define ret (pred key value)) - (when (not ret) - (cont #f)) - (set! last ret)) - dictionary) - last))) - -(define (idict-keys vec dictionary) - (reverse - (dcall dfold vec - (lambda (key value acc) - (cons key acc)) - '() - dictionary))) - -(define (idict-values vec dictionary) - (reverse - (dcall dfold vec - (lambda (key value acc) - (cons value acc)) - '() - dictionary))) - -(define (idict-entries vec dictionary) - (define pair - (dcall dfold vec - (lambda (key value acc) - (cons (cons key (car acc)) - (cons value (cdr acc)))) - (cons '() '()) - dictionary)) - (values (reverse (car pair)) - (reverse (cdr pair)))) - -(define (idict-fold vec proc knil dictionary) - (define acc knil) - (dcall dfor-each vec - (lambda (key value) - (set! acc (proc key value acc))) - dictionary) - acc) - -(define (idict-map->list vec proc dictionary) - (define reverse-lst - (dcall dfold vec - (lambda (key value lst) - (cons (proc key value) lst)) - '() - dictionary)) - (reverse reverse-lst)) - -(define (idict->alist vec dictionary) - (dcall dmap->list vec - cons - dictionary)) - -(define model-vec - (vector - idictionary? idict-empty? idict-contains? idict-ref - idict-ref/default idict-set! idict-adjoin! idict-delete! - idict-delete-all! idict-replace! idict-intern! - idict-update! idict-update/default! idict-pop! idict-map! - idict-filter! idict-remove! idict-search! idict-size - idict-for-each idict-count idict-any idict-every idict-keys - idict-values idict-entries idict-fold idict-map->list - idict->alist)) @@ -1,21 +1,4 @@ -.PHONY: test-guile test-gauche test-kawa test-chibi test-chicken - -test-guile: - guile -L . --r7rs dictionaries-test.scm - -test-gauche: - gosh -I . dictionaries-test.scm - -test-kawa: - cp dictionaries.sld dictionaries.scm - kawa dictionaries-test.scm - rm dictionaries.scm +.PHONY: test-chibi test-chibi: - chibi-scheme dictionaries-test.scm - -test-chicken: - csc -R r7rs -X r7rs -sJ -o dictionaries.so dictionaries.sld - csi -I . -R r7rs -s dictionaries-test.scm - rm dictionaries.so - rm dictionaries.import.scm + docker-compose run --rm chibi diff --git a/plist-impl.scm b/plist-impl.scm deleted file mode 100644 index 262db59..0000000 --- a/plist-impl.scm +++ /dev/null @@ -1,93 +0,0 @@ -(define (register-plist!) - - (define (plist? l) - (and (list? l) - (not (null? l)) - (symbol? (car l)))) - - (define (plist-map! proc plist) - (let loop ((pl plist)) - (cond - ((null? pl) plist) - ((null? (cdr pl)) (error "Malformed plist" plist)) - (else - (let ((key (car pl)) - (value (cadr pl)) - (rest (cddr pl))) - (set-car! (cdr pl) - (proc key value)) - (loop rest)))))) - - (define (plist-filter! pred plist) - (define head (cons #f plist)) - (let loop ((pl plist) - (parent-cell head)) - (cond - ((null? pl) (cdr head)) - ((null? (cdr pl)) (error "Malformed plist" plist)) - (else - (let ((key (car pl)) - (value (cadr pl)) - (rest (cddr pl))) - (if (pred key value) - (loop rest - (cdr pl)) - (loop (begin - (set-cdr! parent-cell rest) - rest) - parent-cell))))))) - - ;; head is a pair, whose cdr is the plist - ;; if found, returns a pair, whose cdr is rest of plist, and cadr is key that was searched for - ;; if not found, returns #f - ;; - ;; the pair indirection is used so that calling set-cdr! on the result allows the plist to be mutated - (define (find-plist-entry key head) - (define plist (cdr head)) - (cond - ((null? plist) #f) - ((equal? key (car plist)) head) - (else (find-plist-entry key (cdr plist))))) - - (define (plist-search! plist key failure success) - (define plist-head (cons #t plist)) - (define (handle-success head) - (define key-cell (cdr head)) - (define val-cell (cddr head)) - (define (update new-key new-value obj) - (set-car! key-cell new-key) - (set-car! val-cell new-value) - (values plist obj)) - (define (remove obj) - (set-cdr! head (cddr (cdr head))) - (values (cdr plist-head) obj)) - (success (car key-cell) (car val-cell) update remove)) - - (define (handle-failure) - (define (insert value obj) - (values (cons key (cons value plist)) - obj)) - (define (ignore obj) - (values plist obj)) - (failure insert ignore)) - (cond - ((find-plist-entry key plist-head) => handle-success) - (else (handle-failure)))) - - (define (plist-size plist) - (/ (length plist) 2)) - - (define (plist-foreach proc plist) - (let loop ((pl plist)) - (if (null? pl) #t - (begin - (proc (car pl) (cadr pl)) - (loop (cddr pl)))))) - - (register-dictionary! - 'dictionary? plist? - 'dict-map! plist-map! - 'dict-filter! plist-filter! - 'dict-search! plist-search! - 'dict-size plist-size - 'dict-for-each plist-foreach)) diff --git a/srfi-125-impl.scm b/srfi-125-impl.scm deleted file mode 100644 index 67da668..0000000 --- a/srfi-125-impl.scm +++ /dev/null @@ -1,93 +0,0 @@ -(define (register-srfi-125!) - - (define (hash-table-set!* table . obj) - (apply hash-table-set! (cons table obj)) - table) - - (define (hash-table-update!* table key updater fail success) - (hash-table-update! table key updater fail success) - table) - - (define (hash-table-update!/default* table key proc default) - (hash-table-update!/default table key proc default) - table) - - (define (hash-table-intern!* table key failure) - (define val (hash-table-intern! table key failure)) - (values table val)) - - (define (hash-table-pop!* table) - (if (hash-table-empty? table) - (error "popped empty dictionary") - (call-with-values - (lambda () (hash-table-pop! table)) - (lambda (key value) (values table key value))))) - - (define (hash-table-delete-all!* table keys) - (for-each - (lambda (key) - (hash-table-delete! table key)) - keys) - table) - - (define (hash-table-map!* proc table) - (hash-table-map! proc table) - table) - - (define (hash-table-filter* proc table) - (hash-table-prune! - (lambda (key value) - (not (proc key value))) - table) - table) - - (define (hash-table-remove!* proc table) - (hash-table-prune! proc table) - table) - - (define (hash-table-search* table key fail success) - (define (handle-success value) - (define (update new-key new-value obj) - (unless (eq? new-key key) - (hash-table-delete! table key)) - (hash-table-set! table new-key new-value) - (values table obj)) - (define (remove obj) - (hash-table-delete! table key) - (values table obj)) - (success key value update remove)) - (define (handle-fail) - (define (ignore obj) - (values table obj)) - (define (insert value obj) - (hash-table-set! table key value) - (values table obj)) - (fail insert ignore)) - - (define default (cons #f #f)) - (hash-table-ref table key handle-fail handle-success)) - - (register-dictionary! - 'dictionary? hash-table? - 'dict-empty? hash-table-empty? - 'dict-contains? hash-table-contains? - 'dict-ref hash-table-ref - 'dict-ref/default hash-table-ref/default - 'dict-set! hash-table-set!* - 'dict-delete-all! hash-table-delete-all!* - 'dict-intern! hash-table-intern!* - 'dict-update! hash-table-update!* - 'dict-update/default! hash-table-update!/default* - 'dict-pop! hash-table-pop!* - 'dict-map! hash-table-map!* - 'dict-filter! hash-table-filter* - 'dict-remove! hash-table-remove!* - 'dict-search! hash-table-search* - 'dict-size hash-table-size - 'dict-for-each hash-table-for-each - 'dict-keys hash-table-keys - 'dict-values hash-table-values - 'dict-entries hash-table-entries - 'dict-fold hash-table-fold - 'dict-map->list hash-table-map->list - 'dict->alist hash-table->alist)) diff --git a/srfi-126-impl.scm b/srfi-126-impl.scm deleted file mode 100644 index 1ba75eb..0000000 --- a/srfi-126-impl.scm +++ /dev/null @@ -1,122 +0,0 @@ -(define (register-srfi-126!) - - (define (hashtable-ref* table key fail success) - (define-values (value found?) (hashtable-lookup table key)) - (if found? - (success value) - (fail))) - - (define (hashtable-ref/default* table key default) - (hashtable-ref table key default)) - - (define (hashtable-set!* table . obj) - (let loop ((obj obj)) - (if (null? obj) - table - (begin - (hashtable-set! table (car obj) (cadr obj)) - (loop (cddr obj)))))) - - (define (hashtable-delete-all!* table keys) - (for-each - (lambda (key) - (hashtable-delete! table key)) - keys) - table) - - (define (hashtable-intern!* table key default) - (define val (hashtable-intern! table key default)) - (values table val)) - - (define (hashtable-update/default!* table key updater default) - (hashtable-update! table key updater default) - table) - - (define (hashtable-pop!* table) - (if (hashtable-empty? table) - (error "popped empty dictionary") - (call-with-values - (lambda () (hashtable-pop! table)) - (lambda (key value) (values table key value))))) - - (define (hashtable-update-all!* proc table) - (hashtable-update-all! table proc) - table) - - (define (hashtable-filter!* proc table) - (hashtable-prune! table - (lambda (key value) - (not (proc key value)))) - table) - - (define (hashtable-remove!* proc table) - (hashtable-prune! table proc) - table) - - (define (hashtable-search* table key fail success) - (define (handle-success value) - (define (update new-key new-value obj) - (unless (eq? new-key key) - (hashtable-delete! table key)) - (hashtable-set! table new-key new-value) - (values table obj)) - (define (remove obj) - (hashtable-delete! table key) - (values table obj)) - (success key value update remove)) - (define (handle-fail) - (define (ignore obj) - (values table obj)) - (define (insert value obj) - (hashtable-set! table key value) - (values table obj)) - (fail insert ignore)) - - (define default (cons #f #f)) - (define found (hashtable-ref table key default)) - (if (eq? default found) - (handle-fail) - (handle-success found))) - - (define (hashtable-for-each* proc table) - (hashtable-walk table proc) - table) - - (define (hashtable-map->lset* proc table) - (hashtable-map->lset table proc)) - - (define (hashtable-keys* table) - (vector->list (hashtable-keys table))) - - (define (hashtable-values* table) - (vector->list (hashtable-values table))) - - (define (hashtable-entries* table) - (call-with-values - (lambda () (hashtable-entries table)) - (lambda (keys vals) - (values - (vector->list keys) - (vector->list vals))))) - - (register-dictionary! - 'dictionary? hashtable? - 'dict-empty? hashtable-empty? - 'dict-contains? hashtable-contains? - 'dict-ref hashtable-ref* - 'dict-ref/default hashtable-ref/default* - 'dict-set! hashtable-set!* - 'dict-delete-all! hashtable-delete-all!* - 'dict-intern! hashtable-intern!* - 'dict-update/default! hashtable-update/default!* - 'dict-pop! hashtable-pop!* - 'dict-map! hashtable-update-all!* - 'dict-filter! hashtable-filter!* - 'dict-remove! hashtable-remove!* - 'dict-search! hashtable-search* - 'dict-size hashtable-size - 'dict-for-each hashtable-for-each* - 'dict-keys hashtable-keys* - 'dict-values hashtable-values* - 'dict-entries hashtable-entries* - 'dict-map->list hashtable-map->lset*)) diff --git a/srfi-69-impl.scm b/srfi-69-impl.scm deleted file mode 100644 index 09f92d2..0000000 --- a/srfi-69-impl.scm +++ /dev/null @@ -1,88 +0,0 @@ -(define (register-srfi-69!) - - (define (hash-table-ref* table key fail success) - (define default (cons #f #f)) - (define found (hash-table-ref/default table key default)) - (if (eq? found default) - (fail) - (success found))) - - (define (hash-table-set!* table . obj) - (let loop ((obj obj)) - (if (null? obj) - table - (begin - (hash-table-set! table (car obj) (cadr obj)) - (loop (cddr obj)))))) - - (define (hash-table-update!/default* table key proc default) - (hash-table-update!/default table key proc default) - table) - - (define (hash-table-delete-all!* table keys) - (for-each - (lambda (key) - (hash-table-delete! table key)) - keys) - table) - - (define (hash-table-foreach* proc table) - (hash-table-walk table proc)) - - (define (hash-table-map* proc table) - (hash-table-walk table (lambda (key value) - (hash-table-set! table key (proc key value)))) - table) - - (define (hash-table-filter* proc table) - (hash-table-walk table - (lambda (key value) - (unless (proc key value) - (hash-table-delete! table key)))) - table) - - (define (hash-table-fold* proc knil table) - (hash-table-fold table proc knil)) - - (define (hash-table-search* table key fail success) - (define (handle-success value) - (define (update new-key new-value obj) - (unless (eq? new-key key) - (hash-table-delete! table key)) - (hash-table-set! table new-key new-value) - (values table obj)) - (define (remove obj) - (hash-table-delete! table key) - (values table obj)) - (success key value update remove)) - (define (handle-fail) - (define (ignore obj) - (values table obj)) - (define (insert value obj) - (hash-table-set! table key value) - (values table obj)) - (fail insert ignore)) - - (define default (cons #f #f)) - (define found (hash-table-ref/default table key default)) - (if (eq? default found) - (handle-fail) - (handle-success found))) - - (register-dictionary! - 'dictionary? hash-table? - 'dict-ref hash-table-ref* - 'dict-ref/default hash-table-ref/default - 'dict-set! hash-table-set!* - 'dict-delete-all! hash-table-delete-all!* - 'dict-contains? hash-table-exists? - 'dict-update/default! hash-table-update!/default* - 'dict-size hash-table-size - 'dict-keys hash-table-keys - 'dict-values hash-table-values - 'dict-map! hash-table-map* - 'dict-filter! hash-table-filter* - 'dict-for-each hash-table-foreach* - 'dict-fold hash-table-fold* - 'dict->alist hash-table->alist - 'dict-search! hash-table-search*)) |
