Package: alexandria

Macro ensure-gethash

Lambda List

ensure-gethash (key hash-table &optional default)

Arguments

key -- an object
table -- a hash table
default -- an object. The default is nil.

Return Value

The values value and present-p.

Details

Acessor which ensures a value for a key in the hash table.

Like the Common Lisp function gethash, but if key is not found in the hash table table saves default under key before returning it. Secondary return value present-p is true if key was already in the hash table.
(defvar table (make-hash-table)) => TABLE
(ensure-gethash 'France table 'Paris) => PARIS, NIL
(gethash 'France table) => PARIS, T