5.4.1.2 Predefined functions on dicts
Dicts currently define the following reserved functions:
- get(?Key)
- Same as Dict.Key, but maps to get_dict/3
instead of
get_dict_ex/3.
This implies that the function evaluation fails silently if Key
does not appear in Dict. See also
:</2, which can be used to
test for existence and unify multiple key values from a dict. For
example:
?- write(t{a:x}.get(a)). x ?- write(t{a:x}.get(b)). false.
- put(+New)
- Evaluates to a new dict where the key-values in New replace or extend the key-values in the original dict. See put_dict/3.
- put(+KeyPath, +Value)
- Evaluates to a new dict where the KeyPath-Value
replaces or extends the key-values in the original dict. KeyPath
is either a key or a term KeyPath/Key,151Note
that we do not use the '.' functor here, because the
would evaluate. replacing the value associated with Key in a sub-dict of the dict on which the function operates. See put_dict/4. Below are some examples:.
/2?- A = _{}.put(a, 1). A = _G7359{a:1}. ?- A = _{a:1}.put(a, 2). A = _G7377{a:2}. ?- A = _{a:1}.put(b/c, 2). A = _G1395{a:1, b:_G1584{c:2}}. ?- A = _{a:_{b:1}}.put(a/b, 2). A = _G1429{a:_G1425{b:2}}. ?- A = _{a:1}.put(a/b, 2). A = _G1395{a:_G1578{b:2}}.