Getting a list of values from a dictionary

Hi,

I am trying to get a list of values from a dictionary given a list of keys.
The best way I have been able to find is:

 A=_{x:1,y:2}, findall(Y,(member(M,[x,y]),Y=A.get(M)),L).

This seems a bit inelegant. Even worse, it uses the order member/2 returns results in, which is afaik no t guaranteed.

Am I missing any obvious better way?

Thank you!

?- A=_{x:1,y:2}, findall(Y,(member(M,[x,y]),Y=A.get(M)),L).
A = _2444{x:1, y:2},
L = [1, 2].
?- A=_{x:1,y:2}, dict_pairs(A,_,P), pairs_values(P,V), dict_keys(P,K).
A = _5736{x:1, y:2},
P = [x-1, y-2],
V = [1, 2],
K = [x, y].
1 Like

Thank you. That is indeed way better.

The appropriate predicates are in two different parts of the manual, and searching for them can be a bit confusing. (Google Search can also confuse things, if you use that rather than the swi-prolog.org search box)

https://www.swi-prolog.org/pldoc/man?section=bidicts
https://www.swi-prolog.org/pldoc/man?section=dicts