9.0
top
← prev up next →

nested-hashπŸ”— i

Kevin R. Stravers

Provides hash-ref and hash-set variants that operate on nested hash tables, that is, a hash table inside a hash table.

procedure

( nested-hash-ref hash*
key...+
[ #:defaultdefault])any?
hash*:hash?
key:any/c
default:any/c =#f
Accesses a hash table recursively using the given keys. default is returned if a key does not exist. An error is raised if an access is performed on a non-hash entry.

procedure

( nested-hash-set hash*
key...+
value
[ #:hashhash])any?
hash*:hash?
key:any/c
value:any/c
hash:any/c =hash
Functionally edits a hash table using the given keys and value. Non-existent keys will automatically become new subtables. Existing intermediate keys that are associated with non-hash values will raise an error. The #:hash keyword specifies a constructor for creating new nested hash tables.

Examples:
> (nested-hash-ref (hash 'a(hash 'b123))'a'b)

123

> (nested-hash-set (hash )'a'b123)

'#hash((a. #hash((b. 123))))

Similarly to the previous functions we have similar functions that take actual lists instead of inline-lists. These may be useful to avoid using apply when generating lists of accesses.

procedure

keys
[ #:defaultdefault])any?
hash*:hash?
keys:(listof any/c )
default:any/c =#f
Accesses a hash table recursively using the given keys. default is returned if a key does not exist. An error is raised if an access is performed on a non-hash entry.

procedure

keys
value
[ #:hashhash])any?
hash*:hash?
keys:(listof any/c )
value:any/c
hash:any/c =hash
Functionally edits a hash table using the given keys and value. Non-existent keys will automatically become new subtables. Existing intermediate keys that are associated with non-hash values will raise an error. The #:hash keyword specifies a constructor for creating new nested hash tables.

Examples:
> (nested-hash-ref* (hash 'a(hash 'b123))'(ab))

123

> (nested-hash-set* (hash )'(ab)123)

'#hash((a. #hash((b. 123))))

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /