Greetings, and while there are quite a threads from users asking about dicts already, it’d be nice to get a neat answer to this very specific question for anyone who turns up here from Google. I’m sure I can’t be the only one who’s stumped!
The documentation reads:
get (?KeyPath, +Default)
Same as get/1 , but if no match is found the function evaluates to Default. If KeyPath contains variables possible choice points are respected and the function only evaluates to Default if the pattern has no matches.
Sounds simple enough, and it’s exactly what I need for my program. But when I try and use it:
?- Dict = en_pl{cat:kot, dog:pies}, X = Dict.get(cat).
Dict = en_pl{cat:kot, dog:pies},
X = cat.
% So far, so good. But...:
?- Dict = en_pl{cat:kot, dog:pies}, X = Dict.get(fish, unknown).
ERROR: fish: No implementation for: <-unknown
% Intended result: X = unknown.
I have no idea why it is looking for <-unknown
or even how I create it—what does the arrow prefix mean? Perhaps someone can explain in simple terms how to use this function (please remember, as anyone could Google this, to provide a general answer without picking at the specifics of my wording—thanks!)