Did you know ... | Search Documentation: |
Pack canny_tudor -- prolog/swi/dicts.pl |
The implementation puts Key and Value in Dict0, unifying the result at Dict. However, if the dictionary Dict0 already contains another value for the indicated Key then it invokes OnNotEmpty with the original Value0 and the replacement Value, finally putting the combined or selected Value_ in the dictionary for the Key.
Merges non-dictionaries according to type. Appends lists when the value in a key-value pair has list type. Only replaces existing values with incoming values when the leaf is not a dictionary, and neither existing nor incoming is a list.
Note the argument order. The first argument specifies the base dictionary starting point. The second argument merges into the first. The resulting merge unifies at the third argument. The order only matters if keys collide. Pairs from Dict1 replace key-matching pairs in Dict0.
Merging does not replace the original dictionary tag. This includes an unbound tag. The tag of Dict0 remains unchanged after merge.
Private predicate merge_dict_/3
is the value merging predicate; given the original Value0 and the
incoming Value, it merges the two values at Value_.
Merging ignores tags.
Keys become tagged keys of the form Tag^Key
. The caret operator
neatly fits by operator precedence in-between the pair operator
(-
) and the sub-key slash delimiter (/
). Nested keys become
nested slash-functor binary compounds of the form
TaggedKeys/TaggedKey
. So for example, the compound Tag^Key-Value
translates to Tag{Key:Value} in dictionary form. Tag^Key-Value
decomposes term-wise as [-, Tag^Key, Value]
. Note that tagged
keys, including super-sub tagged keys, take precedence within the
term.
This is a non-standard approach to dictionary unification. It turns nested sub-dictionary hierarchies into flatten pair-lists of tagged-key paths and their leaf values.
Fails for integer keys because integers cannot serve as functors.
Does not attempt to map integer keys to an atom, since this will
create a reverse conversion disambiguation issue. This does work
for nested integer leaf keys, e.g. a(1)
, provided that the integer
key does not translate to a functor.
The implementation uses atomic concatenation to merge Tag and the dictionary sub-keys. Note that atomic_list_concat/3 works for non-atomic keys, including numbers and strings. Does not traverse sub-lists. Ignores sub-dictionaries where a dictionary value is a list containing dictionaries. Perhaps future versions will.
Creating a dictionary using standard dict_create/3 overrides the tag argument from its Data dictionary, ignoring the Tag if any. For example, using dict_create/3 for tag xyz and dictionary abc{} gives you abc{} as the outgoing dictionary. This predicate reverses this behaviour; the Tag argument replaces any tag in a Data dictionary.
key(Value)
where key
matches
the dictionary key converted to one-two style and lower-case.
Unfolds lists and sub-dictionaries non-deterministically. For most occasions, the non-deterministic unfolding of sub-lists results in multiple non-deterministic solutions and typically has a plural compound name. This is not a perfect solution for lists of results, since the order of the solutions defines the relations between list elements.
Dictionary keys can be atoms or integers. Converts integers to compound names using integer-to-atom translation. However, compounds for sub-dictionaries re-wrap the sub-compounds by inserting the integer key as the prefix argument of a two or more arity compound.