Terms with named arguments (static dicts)
[Note: If you have comments please post them at the Prolog Community Discourse for this PIP]
In this PIP we deal with terms with named arguments, a.k.a. static dicts. See PIP 0102 for the PIP for dynamic dics.
Static dictionaries
Proposal: tag{k1:v1, ..., kn:vn}
maps to
tag(v1, ..., vn)
based on e.g. argnames.
Existing practice
ECLiPSe
See https://www.cs.nmsu.edu/~ipivkina/ECLIPSE/doc/applications.pdf https://www.eclipseclp.org/doc/bips/kernel/syntax/struct-1.html
Called “Named structures”
Declaration:
:- [local/export] struct(tag(k1, ..., kn)).
Usage:
tag{k1:v1, ..., kn:vn}
expands totag(v1,...,vn)
k_i of tag
expands toi
property(arity) of tag
expands ton
property(functor) of tag
expands totag
- subscript syntax
Term[arg1 of tag]
arg(arg1 of tag, Term, Arg)
Term[arg1 of tag]
Ciao
See https://ciao-lang.org/ciao/build/doc/ciao.html/argnames_doc.html
Declaration:
:- argnames tag(k1, ..., kn).
Usage:
tag${k1=>V1,...,kn=>Vn}
expands totag(V1,...,Vn)
, values for missing keys are unbound.tag${/}
expands totag/N
tag${argnames}
expands to list of keys ([k1,...,kn]
)- (expanded as goal)
tag${...,K=>V,...}
with variables in keys are expanded to runtime lookups (similar to likeget_dict/3
) - (expanded as goal)
$~(T, tag${..., k=>V, ...}, NewT)
replace values of specific tags
SWI-Prolog (no dicts of this type)
See https://www.swi-prolog.org/pldoc/man?section=record
Declaration:
:- record tag(arg1[:type1[=default]], arg2, ...)
Access:
tag_arg1(Term, Arg)