% vim set ft=prolog :- module(utils, [ to_assoc/2]). :- use_module(library(assoc)). :- use_module(library(lists)). to_assoc(Obj, Assoc) :- phrase(obj_to_list(Obj), Ls), list_to_assoc(Ls, Assoc). obj_to_list({}(J)) --> conjunction_to_list(J). conjunction_to_list((A,B)) --> !, conjunction_to_list(A), conjunction_to_list(B). conjunction_to_list(K:V) --> [K-V]. % list_to_obj([L|Ls], {}(In), {}(Out)) :- % write('L='),write(L),write(', Ls='),write(Ls),write(', In='),write(In),nl, % list_to_obj(Ls, In, Out0), % write('Out0='),write(Out0),nl, % Out = ','(L, Out0). % list_to_obj([], Obj, Obj) :- % write('Obj='),write(Obj),nl. % % obj_kv(Obj, Key, Value) :- % phrase(obj_to_list(Obj), Ls), % member(Key:Value, Ls). % % obj_set(Obj, Key, Value, Updated) :- % % phrase(obj_to_list(Obj), Ls), % % member(Key:Value, Ls), % % write('Ls='),write(Ls),nl, % % LsU = [Key:Value|Ls], % % write('LsU='),write(LsU),nl, % % Updated = {LsU}. % list_to_obj([Key:Value], Obj, Updated).