(html (head (title "sph-lib (sph hashtable)") (link (@ (rel "icon") (href "data:,"))) (meta (@ (name "viewport") (content "width=device-width,initial-scale=1"))) (link (@ (rel "stylesheet") (type "text/css") (href "/css/sph.css"))) #f) (body () (div (@ (class top)) (nav (a (@ (href "/")) "start") ", " (a (@ (href "/feed.xml")) "feed")) "") (div (@ (class "middle")) (div (@ (class mtime) (title "last modification time of the current page")) "2025-08-29") (section (h1 "(sph hashtable)") (div (p "rnrs-hashtable processing.") (p "part of " (a (@ (href "../../sph-lib.html")) "sph-lib")) ((section (@ (class "library-description")) (h1 "library description") (div (p "syntax") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "ht-bind :: hashtable (key ...) body ... -> any")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "selectively bind keys of hashtable to variables.")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "keys are unquoted literals.")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "example: (ht-bind my-ht (a b c) (+ 1 c b a))")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "ht-ref :: hashtable key [default] -> any")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "rnrs ht-ref with an optional default argument")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "ht-ref-q :: hashtable hashtable key -> any")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "key is implicitly quoted")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "ht-create-symbol :: associations ...")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "create a hashtable optimised for symbol keys")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "ht-bind :: values ...")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "equivalent to (ht-create-symbol (q name) name ...)")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "ht-create-eq")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp") (*ENTITY* "nbsp")) "create a hashtable that uses eq? as a comparison function")))) (section (@ (class "library-name")) (h1 "module name") (p "(sph hashtable)")) (section (@ (class "library-exports")) (h1 "exported bindings") (div (div (@ (class "doc-bindings")) (div (@ (id "doc-b-" "ht-alist") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-alist") " " (span (@ (class "first-sig")) "ht [depth] ->")) (div (@ (class "rest-sig")) (div "rnrs-hashtable [integer] -> list")) (div (@ (class "description")) (("converts a hashtable to an alist. if depth is greater than 0 any other" (br) "hashtables being values up to this nesting depth will be converted too." (br) "scheme has a value for infinite that can be used as depth")))) (div (@ (id "doc-b-" "ht-bind") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-bind") " " (span (@ (class "first-sig")) "ht (key ...) body ...")) "" "") (div (@ (id "doc-b-" "ht-clear!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-clear!") " " (span (@ (class "first-sig")) "hashtable [k] ->")) "" "") (div (@ (id "doc-b-" "ht-contains?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-contains?") " " (span (@ (class "first-sig")) "hashtable key ->")) "" "") (div (@ (id "doc-b-" "ht-copy") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-copy") " " (span (@ (class "first-sig")) "hashtable [mutable] ->")) "" "") (div (@ (id "doc-b-" "ht-copy*") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-copy*") " " (span (@ (class "first-sig")) "a f ->")) "" (div (@ (class "description")) (("call f with a copy of hashtable and return it")))) (div (@ (id "doc-b-" "ht-copy-empty") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-copy-empty") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "hashtable -> hashtable")) (div (@ (class "description")) (("creates a new empty hashtable with the same equivalence and hash function as the input hashtable.")))) (div (@ (id "doc-b-" "ht-create") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-create") " " (span (@ (class "first-sig")) "associations ... ->")) "" (div (@ (class "description")) (("{key value} ... -> hashtable" (br) "creates a hashtable." (br) "example: (hashtable 'a 1 'b 2 'c 3)")))) (div (@ (id "doc-b-" "ht-create-binding") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-create-binding")) "" "") (div (@ (id "doc-b-" "ht-create-eq") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-create-eq")) "" "") (div (@ (id "doc-b-" "ht-create-eqv") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-create-eqv")) "" "") (div (@ (id "doc-b-" "ht-create-string") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-create-string")) "" "") (div (@ (id "doc-b-" "ht-create-symbol") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-create-symbol")) "" "") (div (@ (id "doc-b-" "ht-create-symbol-q") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-create-symbol-q")) "" "") (div (@ (id "doc-b-" "ht-delete!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-delete!") " " (span (@ (class "first-sig")) "hashtable key ->")) "" "") (div (@ (id "doc-b-" "ht-each") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-each") " " (span (@ (class "first-sig")) "proc ht ->")) (div (@ (class "rest-sig")) (div "procedure:{key value ->} hashtable ->")) (div (@ (class "description")) (("call proc for each key and value association in hashtable")))) (div (@ (id "doc-b-" "ht-each-key") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-each-key") " " (span (@ (class "first-sig")) "proc ht")) "" "") (div (@ (id "doc-b-" "ht-entries") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-entries") " " (span (@ (class "first-sig")) "hashtable ->")) "" "") (div (@ (id "doc-b-" "ht-equivalence-function") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-equivalence-function") " " (span (@ (class "first-sig")) "hashtable ->")) "" "") (div (@ (id "doc-b-" "ht-fold") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-fold") " " (span (@ (class "first-sig")) "proc init a ->")) (div (@ (class "rest-sig")) (div "procedure:{key value state -> state} any hashtable -> list")) "") (div (@ (id "doc-b-" "ht-fold-right") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-fold-right") " " (span (@ (class "first-sig")) "proc init a ->")) (div (@ (class "rest-sig")) (div "procedure:{key value state -> state} any hashtable -> list")) "") (div (@ (id "doc-b-" "ht-from-alist") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-from-alist") " " (span (@ (class "first-sig")) "a #:equal-f #:hash-f #:depth ->")) (div (@ (class "rest-sig")) (div "list #:equal-f procedure #:hash-f procedure #:depth integer/infinite -> hashtable")) (div (@ (class "description")) (("convert alist 'a' to an r6rs hashtable." (br) "if depth is positive then also convert nested alists to hashtables at most depth nestings deep." (br) "depth can be (inf)")))) (div (@ (id "doc-b-" "ht-from-list") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-from-list") " " (span (@ (class "first-sig")) "a [equal-proc hash-proc] ->")) "" (div (@ (class "description")) (("convert a list to an r6rs standard library hashtable. nested lists are not converted to a hash." (br) "example" (br) "(ht-ref (ht-from-list (list 'a 1 'b 2)) 'b #f)" (br) "-> 2")))) (div (@ (id "doc-b-" "ht-from-tree") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-from-tree") " " (span (@ (class "first-sig")) "a [equal-proc hash-proc] ->")) (div (@ (class "rest-sig")) (div "list [procedure:{a b -> boolean} procedure] -> rnrs-hashtable")) (div (@ (class "description")) (("like ht-from-list but also converts nested lists to nested hashtables")))) (div (@ (id "doc-b-" "ht-hash-equal") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-hash-equal") " " (span (@ (class "first-sig")) "obj [size] ->")) "" "") (div (@ (id "doc-b-" "ht-hash-function") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-hash-function") " " (span (@ (class "first-sig")) "hashtable ->")) "" "") (div (@ (id "doc-b-" "ht-hash-string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-hash-string") " " (span (@ (class "first-sig")) "a [b c d] ->")) "" "") (div (@ (id "doc-b-" "ht-hash-symbol") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-hash-symbol") " " (span (@ (class "first-sig")) "obj [size] ->")) "" "") (div (@ (id "doc-b-" "ht-invert!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-invert!") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "hashtable -> hashtable")) (div (@ (class "description")) (("use values as keys and keys as values")))) (div (@ (id "doc-b-" "ht-keys") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-keys") " " (span (@ (class "first-sig")) "hashtable ->")) "" "") (div (@ (id "doc-b-" "ht-list-replace") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-list-replace") " " (span (@ (class "first-sig")) "a ht ->")) (div (@ (class "rest-sig")) (div "list rnrs-hashtable -> list")) (div (@ (class "description")) (("replaces elements in list that exist as key in a hashtable with the associated value." (br) "if the value is a list, the element is either removed (empty list) or replaced with multiple elements")))) (div (@ (id "doc-b-" "ht-make") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-make") " " (span (@ (class "first-sig")) "hash-function equiv [k] ->")) "" "") (div (@ (id "doc-b-" "ht-make-eq") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-make-eq") " " (span (@ (class "first-sig")) "[k] ->")) "" "") (div (@ (id "doc-b-" "ht-make-eqv") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-make-eqv") " " (span (@ (class "first-sig")) "[k] ->")) "" "") (div (@ (id "doc-b-" "ht-make-string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-make-string") " " (span (@ (class "first-sig")) "[size] ->")) "" "") (div (@ (id "doc-b-" "ht-map!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-map!") " " (span (@ (class "first-sig")) "proc a ->")) (div (@ (class "rest-sig")) (div "hashtable -> hashtable")) "") (div (@ (id "doc-b-" "ht-merge!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-merge!") " " (span (@ (class "first-sig")) "a b ... ->")) (div (@ (class "rest-sig")) (div "hashtable hashtable ... -> unspecified")) (div (@ (class "description")) (("copy the values of hash b to hash a. existing key values are overwritten")))) (div (@ (id "doc-b-" "ht-object") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-object") " " (span (@ (class "first-sig")) "a [default] ->")) (div (@ (class "rest-sig")) (div "hashtable [any:default] -> procedure:{any:key -> any:value/default}")) "") (div (@ (id "doc-b-" "ht-ref") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-ref") " " (span (@ (class "first-sig")) "h k d")) "" "") (div (@ (id "doc-b-" "ht-ref-q") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-ref-q") " " (span (@ (class "first-sig")) "h k d")) "" "") (div (@ (id "doc-b-" "ht-select") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-select") " " (span (@ (class "first-sig")) "a keys ->")) "" "") (div (@ (id "doc-b-" "ht-set!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-set!") " " (span (@ (class "first-sig")) "hashtable key obj ->")) "" "") (div (@ (id "doc-b-" "ht-set-multiple!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-set-multiple!") " " (span (@ (class "first-sig")) "ht assoc ... ->")) "" (div (@ (class "description")) (("hashtable key/value ..." (br) "return a new hashtable with multiple values having been added or updated")))) (div (@ (id "doc-b-" "ht-set-multiple-q!") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-set-multiple-q!") " " (span (@ (class "first-sig")) "a key/value ...")) "" (div (@ (class "description")) (("hashtable [any:unquoted-key any:value] ...")))) (div (@ (id "doc-b-" "ht-set-q!") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-set-q!") " " (span (@ (class "first-sig")) "h k v")) "" "") (div (@ (id "doc-b-" "ht-size") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-size") " " (span (@ (class "first-sig")) "hashtable ->")) "" "") (div (@ (id "doc-b-" "ht-tree-and-ref") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-tree-and-ref") " " (span (@ (class "first-sig")) "h k")) "" "") (div (@ (id "doc-b-" "ht-tree-and-ref-q") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-tree-and-ref-q") " " (span (@ (class "first-sig")) "a key ...")) "" "") (div (@ (id "doc-b-" "ht-tree-contains?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-tree-contains?") " " (span (@ (class "first-sig")) "a keys ... ->")) "" "") (div (@ (id "doc-b-" "ht-tree-copy") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-tree-copy") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "ht-tree-copy*") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-tree-copy*") " " (span (@ (class "first-sig")) "a proc ->")) "" "") (div (@ (id "doc-b-" "ht-tree-merge!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-tree-merge!") " " (span (@ (class "first-sig")) "a b ... ->")) (div (@ (class "rest-sig")) (div "hashtable ... -> unspecified")) (div (@ (class "description")) (("merges hashtables b from right to left into a. nested hashtables are merged recursively")))) (div (@ (id "doc-b-" "ht-tree-ref") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-tree-ref") " " (span (@ (class "first-sig")) "h k")) "" "") (div (@ (id "doc-b-" "ht-tree-ref-q") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-tree-ref-q") " " (span (@ (class "first-sig")) "a key ...")) "" "") (div (@ (id "doc-b-" "ht-tree-set!") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "ht-tree-set!") " " (span (@ (class "first-sig")) "h k v")) "" "") (div (@ (id "doc-b-" "ht-update-multiple!") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-update-multiple!") " " (span (@ (class "first-sig")) "ht keys proc ->")) (div (@ (class "rest-sig")) (div "hashtable list procedure:{any:values ... -> (any:new-values ...)} -> hashtable")) (div (@ (class "description")) (("set values for 'keys' in hashtable to new values by mapping using 'proc'")))) (div (@ (id "doc-b-" "ht-values") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht-values") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "hashtable -> vector")) "") (div (@ (id "doc-b-" "ht?") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ht?") " " (span (@ (class "first-sig")) "obj ->")) "" "") (div (@ (id "doc-b-" "sph-hashtable-description") (class "doc-b")) (div (span (@ (class "type")) "variable") ": " (span (@ (class "name")) "sph-hashtable-description")) "" "")))))))) ()))