I’ve been playing around with using dicts materialized from json recently and keep getting caught out with how best to extract values from them.
The partial unification syntax lets us do something like:
?- _{name:N} :< _{name:bob, age:21}.
N = bob.
However this partial unification breaks down in child dicts. e.g.
?- _{ value:_{name:N} } :< _{ value:_{name:bob, age:21} }.
false.
% Needs full unification
?- _{ value:_{name:N, age:A} } :< _{ value:_{name:bob, age:21} }.
N = Bob,
A = 21.
So if the JSON API has optional fields or in future is extended with fields and one has converted the response into a dict, its unsafe to unify against data within a child dicts.
Which means: to be sure of extracting the data you want, you need to break the unification over multiple steps by extracting subdicts, and their subdicts etc and unify against those.
?- _{ value:Person } :< _{ value:_{name:bob, age:21} }, _{ name:Name } :< Person.
Person = _7896{age:21, name:bob},
Name = bob.
Shouldn’t the :< operator also be applied at subdict levels also, in which case the failed examples would succeed?