5.4.4 A motivation for dicts as primary citizens
Dicts, or key-value associations, are a common data structure. A good old example are property lists as found in Lisp, while a good recent example is formed by JavaScript objects. Traditional Prolog does not offer native property lists. As a result, people are using a wide range of data structures for key-value associations:
- Using compound terms and positional arguments, e.g.,
point(1,2)
. - Using compound terms with library
library(record)
, which generates access predicates for a term using positional arguments from a description. - Using lists of terms
Name=Value
,Name-Value
,Name:Value
orName(Value)
. - Using library
library(assoc)
which represents the associations as a balanced binary tree.
This situation is unfortunate. Each of these have their advantages
and disadvantages. E.g., compound terms are compact and fast, but
inflexible and using positional arguments quickly breaks down. Library
library(record)
fixes this, but the syntax is considered
hard to use. Lists are flexible, but expensive and the alternative
key-value representations that are used complicate the matter even more.
Library
library(assoc)
allows for efficient manipulation of
changing associations, but the syntactical representation of an assoc is
complex, which makes them unsuitable for e.g., options lists as
seen in predicates such as open/4.