Next: , Previous: , Up: srfi hash-tables spec   [Index] Type constructors and predicate

Function: make-hash-table
Function: make-hash-table equal?
Function: make-hash-table equal? hash
Function: make-hash-table equal? hash arg ...

Create a new hash table with no associations. equal? is a predicate that should accept two keys and return a boolean telling whether they denote the same key value; it defaults to equal?.

hash is a hash function, and defaults to an appropriate hash function for the given equal? predicate (see srfi hash-tables spec hashing). However, an acceptable default is not guaranteed to be given for any equivalence predicate coarser than equal?, except for string-ci=?.3 The function hash must be acceptable for equal?, so if we use coarser equivalence than equal? other than string-ci=?, we must always provide the function hash ourself.

Implementations are allowed to use the rest args for implementation–specific extensions. Be warned, though, that using these extensions will make our program less portable.

Function: hash-table? obj

A predicate to test whether a given object obj is a hash table; return a boolean. The hash table type should be disjoint from all other types, if possible.

Function: alist->hash-table alist
Function: alist->hash-table alist equal?
Function: alist->hash-table alist equal? hash
Function: alist->hash-table alist equal? hash arg ...

Take an “association list” alist and create a hash table hash-table which maps the car of every element in alist to the cdr of corresponding elements in alist.

equal?, hash, and args are interpreted as in make-hash-table. If some key occurs multiple times in alist, the value in the first association will take precedence over later ones. (Note: the choice of using cdr (instead of cadr) for values tries to strike balance between the two approaches: using cadr would render this procedure unusable for cdr alists, but not vice versa.)

The rest args are passed to make-hash-table and can thus be used for implementation–specific extensions.



An equivalence predicate C1 is coarser than a equivalence predicate C2 iff there exist values X and Y such that (and (C1 X Y) (not (C2 X Y))).

Next: , Previous: , Up: srfi hash-tables spec   [Index]