Module dict

This module provides tagged structure access. Tagged structures are also known as Prolog dicts. They have their own syntax as either an empty dict Term0 {} or a non-empty dict Term0 { Term1 } which are short-hands for ordinary compounds. When this module is imported, the syntax will be enabled in the importing module.

Examples:
?- X = point{y:2, x:1}.
X = point{x:1,y:2}
?- point{y:2, x:1} = point{x:1, y:2}.
Yes

The keys inside tagged structures are not restricted to any Prolog term category. All that is required is that they are ground. With the introduction of function expansion in the Jekejeke Prolog runtime library, the tagged structures will be automatically pre-sorted during consult. This assures that they are equal even if they differ in their key order.

Example:
?- P = point{x:1,y:2}, get_dict(y, P, Y).
Y = 2
?- P = point{x:1,y:2}, Tag{y:Y} :< P.
Tag = point,
Y = 2

The set of predicates for tagged structures is modelled after the corresponding SWI-Prolog library for Prolog dicts. We have adopted most of the instantiation checks and most of the type checks. The tagged structures can be also used in connection with the dot notation. This func-tionality is provided through the module "func".

The following dicts predicates are provided:

is_dict(X):
The predicate succeeds when X is a tagged structure.
is_dict(X, T):
The predicate succeeds when X is a tagged structure and when T unifies with the tag of the tagged structure.
dict_pairs(X, T, L):
The predicate succeeds in X with the tagged structure that has tag T and key value pairs L.
get_dict(K, S, V):
The predicate succeeds with the value V of the key K in the tagged structure S.
S :< T:
The predicate succeeds when the tags of S and T unify and when the key value pairs of the tagged structure S appear in the tagged structure T.
S >:< T:
The predicate succeeds when the tags of S and T unify and when the values for the common keys of S and T unify.
del_dict(K, S, V, T):
The predicate succeeds in T with the deletion of the key K from the tagged structure S and in V with the old value.
select_dict(S, T, R):
The predicate succeeds when the tags of S and T unify and when R unifies with a fresh tag and the removal of the key value pairs of S from the tagged structure T.
put_dict(K, S, V, T):
The predicate succeeds in T with the replacement of the new value V for the key K by in the tagged structure S.
put_dict(S, T, R):
The predicate succeeds in R with the replacement of the key value pairs of S in the tagged structure T.

Kommentare