Hey all,
I want to iterate over a possibly nested dict and apply some transformation on it’s atomic members, so I tried something along these lines:
transformed(D0, D) :-
del_dict(Key, D0, Value0, D1),
( atomic(Value0) -> foo(Value0, Value)
; transformed(Value0, Value)
),
transformed(D1, D2),
put_dict(Key, D2, Value, D).
But, this approach doesn’t work as del_dict/4 throws an instantiation error:
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.26)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?- D0 = dict{a:b}, del_dict(A, D0, B, D).
ERROR: Arguments are not sufficiently instantiated
ERROR: In:
ERROR: [11] del_dict(_26520,dict{a:b},_26524,_26526)
ERROR: [10] '<meta-call>'(user:user: ...) <foreign>
ERROR: [9] toplevel_call(user:user: ...) at /opt/local/lib/swipl/boot/toplevel.pl:1115
?-
Is this the behavior of del_dict/4 intended?
Compare to get_dict/3, which doesn’t throw and instead unifies A with some key:
?- D = dict{a:b}, get_dict(A, D, B).
D = dict{a:b},
A = a,
B = b.
What would be the recommended way to perform such a dict transformation?
Thanks.