The next figure lists some defined names that are applicable to hash tables. The following rules apply to hash tables.
eq,
those whose keys are compared with eql,
those whose keys are compared with equal, and
those whose keys are compared with equalp.
make-hash-table.
gethash is used to look up a key and find the associated value.
New entries are added to hash tables using setf with gethash.
remhash is used to remove an entry.
For example:
(setq a (make-hash-table)) → #<HASH-TABLE EQL 0/120 32536573> (setf (gethash 'color a) 'brown) → BROWN (setf (gethash 'name a) 'fred) → FRED (gethash 'color a) → BROWN, true (gethash 'name a) → FRED, true (gethash 'pointy a) → NIL, false
In this example, the symbols color and name are being used as
keys, and the symbols brown and fred are being used as the
associated values. The hash table
has two items in it, one of which
associates from color to brown, and the other of which
associates from name to fred.
gethash.