File "dict"

This module provides Prolog dict access and modification. Unlike a JSON term, a Prolog dict accepts arbitrary Prolog terms as keys and values. The predicate dict_current/3 allows accessing a value from a Prolog dict by a key. The predicates dict_set/4 and dict_remove/4 are non-destructive and create a new Prolog dict.

In reflection of how dicts typcially behave in other programming languages such as JavaScript and Python, our realization preserves the input order of modifications. The input order is also reflected in the bi-directional predicate dict_pairs/2 as well. This behaviour is unlike SWI-Prolog which keeps Prolog dicts key sorted.

The following Prolog dict predicates are provided:

dict_pairs(S, T):
The predicate succeeds in T with the key value pair list from the Prolog dict S.
dict_size(T, S):
The predicate succeeds in S with the number of key value pairs of the Prolog dict T.
dict_current(T, K, V):
The predicate succeeds in V with the value for the key K in the Prolog dict T.
dict_set(T, K, V, S):
The predicate succeeds. It succeeds in S with the Prolog dict T extended by the key value pair K,V if the key is new or else the value for the K replaced by V.
dict_add(T, K, V, S):
The predicate succeeds if the key is new. It succeeds in S with the Prolog dict T extended by the key value pair K,V.
dict_remove(T, K, S):
The predicate succeeds in S with the dict after removing the value for the key K in the dict T.

Kommentare