store_update(Store, Key, OldValue, NewValue) :- with_mutex(Store, ( store_get(Store, Key, Entry), store_set(Store, Key, NewValue), OldValue = Entry % after update! )).
The key can be arbitrarily complex, but must be a ground term. The value can be an arbitrary term, and may contain uninstantiated variables. Note that values are copied when being stored or retrieved, therefore a retrieved nonground value will contain fresh variables rather than the original ones (this is similar to the behaviour of bags, shelves and global variables).
The complexity of the update operation is linear in the size of the key and both values, which are copied. For indexing purposes, a hash value is computed from the key, and the full depth of the key is taken into account.
Note: If StoreHandle is not a handle, then it must be an atom or a compound term, and the store is identified by this term's toplevel functor together with the context module.
?- store_create(Handle), store_update(Handle, tom, Old, first). % no entry yet No (0.00s cpu) ?- store_create(Handle), store_set(Handle, tom, first), store_update(Handle, tom, Old, second), store_get(Handle, tom, New). Handle = $&(store,"17h3") Old = first New = second Yes (0.00s cpu) No (0.00s cpu)