3 ms·
What about integers being keys. That works fine. How does a 3 level deep map work with clauses The most straightforward manner is like you would do this in a
by danieldk 13y ago
What about integers being keys.
That works fine.
How does a 3 level deep map work with clauses
The most straightforward manner is like you would do this in a relational database (if the goal is to keep O(1) times). E.g. two-level:
foo(a,x).
foo(b,y).
bar(x,a-x-one).
bar(x,a-x-two).
bar(y,b-y-one).
Again, you can add predicates to make this less unwieldy.
If the JSON conforms to a schema, there is also the possibility of mapping particular keys to arguments. Since you know the set of possible keys in such a case, you could map keys to fixed term arguments. E.g. a structure such as:
{ "foo": "apple", "bar": "pear" }
Could be mapped to:
json(apple,pear)
You would have the same You could do this for deeper maps as well. It gives you the same benefits as hash maps, O(1) indexing. In fact, the Hdrug[1] system uses such a representation for partially typed feature structures, which can have an arbitrary depth. It provides a DSL for easily specifying types (the 'schema') and unifying structures and substructures. There is also a short description in the introductory chapters of my thesis, though it is definitely not my work ;).
Note: I am not for or against adding maps to the language. There are probably applications where they are very handy in Prolog. For the things I worked on in Prolog I never really needed first-class maps.
[1] http://www.let.rug.nl/~vannoord/Hdrug/ http://www.let.rug.nl/~vannoord/Hdrug/
[2] http://danieldk.eu/Research/Publications/phd-thesis.pdf http://danieldk.eu/Research/Publications/phd-thesis.pdf (starting at the end of page 19)