5.4.1 Dict types and tags
The PIP
implementors forum is working on three PIPs related to dicts and their
syntax: 0102, 0104 and 0109. These PIPs are converging to the following
consensus regarding the Tag{...} syntax:
- The ... in
Tag{...}is a set of Key:Value, where Key is an atom (and possibly (small) integer) and Value is any term. This is compatible to SWI-Prolog. - The Tag is either
- The atom
. This denotes a dynamic dict, which is what our dicts are.# - Any other atom. This denotes a named arguments or struct. This syntax is mapped to a compound term whose arity and allowed keys is defined by a declaration.
- A variable. This is parsed into an attributed variable (see section 8.1).
- The atom
Our aim is to support these PIPs. Next to mapping “any other
atom” to a named argument structure, we will support mapping these
to a dynamic dict, optionally with user-defined functions (see
section 5.4.2.1). The
transition is guided by the Prolog flag var_tag.
Its current default (dict) is compatible with the original
dict implementation of SWI-Prolog.
The use of unbound tags is deprecated. It is recommended to use
for anonymous dynamic dicts. The main reason for using unbound tags is
in using them with the predicates :</2
and >:</2 to access
a set of keys in a dict with unknown tag. In the current version the #
tag matches any tag in these predicates. For example, to extract the #x
and y from a dict, we can now use
...,
#{x:X, y:Y} :< Dict,