summaryrefslogtreecommitdiff
path: root/7/utils.pl
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2023-11-23 10:49:21 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2023-11-23 10:49:21 +0100
commit2583897e4c5cbe56525365206c2a64bcd0c75e5f (patch)
treea98e8c51917e7690a79c939d16c46c9bf837cfb4 /7/utils.pl
parent3d1c40ea667a25c1dde11a44a9e2e87a8cf51112 (diff)
downloadprolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.gz
prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.bz2
prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.tar.xz
prolog-firewall-2583897e4c5cbe56525365206c2a64bcd0c75e5f.zip
wip
Diffstat (limited to '7/utils.pl')
-rw-r--r--7/utils.pl41
1 files changed, 41 insertions, 0 deletions
diff --git a/7/utils.pl b/7/utils.pl
new file mode 100644
index 0000000..ecef72d
--- /dev/null
+++ b/7/utils.pl
@@ -0,0 +1,41 @@
+% 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).