All Manuals > LispWorks® User Guide and Reference Manual > 37 The HCL Package

ensure-hash-entry Function

Summary

Gets a value from a hash-table, adding a new value if this fails, all with the table locked.

Package

hcl

Signature

ensure-hash-entry key hash-table new-value &optional in-lock-constructor => result

Arguments
key
A Lisp object.
hash-table
new-value
A Lisp object.
in-lock-constructor
A function designator for a function of one argument.
Values
result
A Lisp object.
Description

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.

Notes

ensure-hash-entry is quite inefficient because it always locks the hash table. Normally you should use with-ensuring-gethash or gethash-ensuring instead.

See also

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