Gets a value from a hash-table, adding a new value if this fails, all with the table locked.
hcl
ensure-hash-entry key hash-table new-value &optional in-lock-constructor => result
key⇩ |
A Lisp object. |
hash-table⇩ |
A hash-table. |
new-value⇩ |
A Lisp object. |
in-lock-constructor⇩ |
A function designator for a function of one argument. |
result |
A Lisp object. |
The function ensure-hash-entry
gets the value for the key key in the hash table hash-table, and if this fails puts a new value new-value in hash-table and returns it. ensure-hash-entry
does all this with hash-table locked.
If the key key is not found, then if in-lock-constructor is non-nil then in-lock-constructor is called with new-value as its argument, and the result is put in the table and returned. If key is not found and in-lock-constructor is nil
, new-value is put in the table and returned.
ensure-hash-entry
is quite inefficient because it always locks the hash table. Normally you should use with-ensuring-gethash or gethash-ensuring instead.
gethash-ensuring
with-ensuring-gethash
19.5 Modifying a hash table with multiprocessing
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:35