hashtable-ref - get a value from a hashtable
(import (rnrs)) ;R6RS
(import (rnrs hashtables)) ;R6RS
(hashtable-ref hashtable key default)
Returns the value in hashtable associated with key. If
hashtable does not contain an association for key,
default is returned.
Returns a single object; either a value from an association in hashtable
or the object default.
(define ht (make-eq-hashtable))
(hashtable-set! ht 'foo 'bar)
(hashtable-ref ht 'foo #f) => bar
(hashtable-ref ht 'bar #f) => #f
This procedure is unique to R6RS. Similar procedures exist in SRFI-69 and
SRFI-125.
This procedure can raise exceptions with the following condition types:
- &assertion (R6RS)
- The wrong number of arguments was passed or an argument was outside its
domain. In particular, hashtable should be a hashtable and
key should be in the domain of the hashtable's hash and equal
functions.
This procedure first appeared in R6RS. An equivalent procedure already existed
in SRFI-69 under the name hash-table-ref.
The following code pattern does not work if the hashtable's keys can be
associated with the false object.
(cond ((hashtable-ref ht key #f) =>
(lambda (value)
(... do something with value ...)))
(else
... assume key is not in ht ...))
Use hashtable-contains?(3scm) to get around this
problem.