
dicts.pl -- Dict utilitiesThis library defines utilities that operate on lists of dicts, notably to make lists of dicts consistent by adding missing keys, converting between lists of compounds and lists of dicts, joining and slicing lists of dicts.
mapdict(:Goal, +Dict)
mapdict(:Goal, ?Dict, ?Dict2)
mapdict(:Goal, ?Dict, ?Dict2, ?Dict3)call(Goal, Key,
V1, ...) is true for all keys in the dicts. At least one of the
dicts must be instantiated.
dicts_same_tag(+List, -Tag) is semidet
dict_size(+Dict, -KeyCount) is det
dict_keys(+Dict, -Keys) is det
dicts_same_keys(+List, -Keys) is semidet
dicts_to_same_keys(+DictsIn, :OnEmpty, -DictsOut)call(:OnEmpty, +Key, +Dict, -Value)
dict_fill(+ValueIn, +Key, +Dict, -Value) is det
?- dicts_to_same_keys([r{x:1}, r{y:2}], dict_fill(null), L).
L = [r{x:1, y:null}, r{x:null, y:2}].
?- dicts_to_same_keys([r{x:1}, r{y:2}], dict_fill(_), L).
L = [r{x:1, y:_G2005}, r{x:_G2036, y:2}].
Use dict_no_fill/3 to raise an error if a dict is missing a key.
dicts_join(+Key, +DictsIn, -Dicts) is semidet
?- dicts_join(x, [r{x:1, y:2}, r{x:1, z:3}, r{x:2,y:4}], L).
L = [r{x:1, y:2, z:3}, r{x:2, y:4}].
dicts_join(+Key, +Dicts1, +Dicts2, -Dicts) is semidet
?- DL1 = [r{x:1,y:1},r{x:2,y:4}],
DL2 = [r{x:1,z:2},r{x:3,z:4}],
dicts_join(x, DL1, DL2, DL).
DL = [r{x:1, y:1, z:2}, r{x:2, y:4}, r{x:3, z:4}].
dicts_slice(+Keys, +DictsIn, -DictsOut) is det
dicts_to_compounds(?Dicts, +Keys, :OnEmpty, ?Compounds) is semidetrow is used. For example:
?- Dicts = [_{x:1}, _{x:2, y:3}],
dicts_to_compounds(Dicts, [x], dict_fill(null), Compounds).
Compounds = [row(1), row(2)].
?- Dicts = [_{x:1}, _{x:2, y:3}],
dicts_to_compounds(Dicts, [x,y], dict_fill(null), Compounds).
Compounds = [row(1, null), row(2, 3)].
?- Compounds = [point(1,1), point(2,4)],
dicts_to_compounds(Dicts, [x,y], dict_fill(null), Compounds).
Dicts = [point{x:1, y:1}, point{x:2, y:4}].
When converting from Dicts to Compounds Keys may be computed by dicts_same_keys/2.
The following predicates are exported, but not or incorrectly documented.
dict_no_fill(Arg1, Arg2, Arg3)
mapdict(Arg1, Arg2, Arg3)
mapdict(Arg1, Arg2, Arg3, Arg4)