Missed opportunity:
The predicate fails if Assoc
is set but Pairs
is fresh, i.e. doesn't work "backwards", as the mode flags indicate.
It doesn't even throw in that case ... this is really unfortunate.
Use assoc_to_list/2 instad
% Simple call ?- list_to_assoc([0-a,2-c,1-d],Assoc). Assoc = t(1, d, -, t(0, a, -, t, t), t(2, c, -, t, t)). % Try to run it backwards. NOPE! It just fails. ?- list_to_assoc([0-a,2-c,1-d],Assoc),list_to_assoc(L,Assoc). false. % Use assoc_to_list for the "backwards" part. ?- list_to_assoc([0-a,2-c,1-d],Assoc),assoc_to_list(Assoc,L). Assoc = t(1, d, -, t(0, a, -, t, t), t(2, c, -, t, t)), L = [0-a, 1-d, 2-c].