table-lookup -- Searches a table for the given key

Type: generic


table-lookup( table key, value);



An instance of <table> to be searched


The key for which to search. Must be an instance of the key class appropriate for the given table.

Return Values


The value associated with given key, or #f if the key is not present in the table[1].


This generic function on tables is used to search for the presence of a given key in a table.

The given key must be compatible with the table, or an error is signalled.

The following method searches a generic hash table (ie, with arbitrary test and hash functions) for the given key.

The given key is first handed to the table's hash function to compute a hash code. If the hash function does not return a <fixnum>, then an error is signalled.

The hash code is then sought in the table; if found, then the test function is called with two arguments, the first being the key in the table that has the same hash code, and the second being the key given to table-lookup. If that function returns non-#f, then the two keys are considered equal and a "table hit" has occurred.


table-lookup( generic-table key, value);



Note that therefore, if #f is the value associated with a given key, you can't tell by the return value of table-lookup whether or not the value is present. table-lookup should probably be changed to return no values in that case instead, although that becomes #f in a value-expecting context anyway. In any case, the table-key-present? solves the problem at the cost of an extra lookup