summaryrefslogtreecommitdiff
path: root/repl.pl
diff options
context:
space:
mode:
Diffstat (limited to 'repl.pl')
-rw-r--r--repl.pl25
1 files changed, 23 insertions, 2 deletions
diff --git a/repl.pl b/repl.pl
index 0a3d5d2..c7d3a34 100644
--- a/repl.pl
+++ b/repl.pl
@@ -35,8 +35,9 @@ read_eval_print :-
!,
abolish(found_a_solution/0).
-eval_and_print(Goal, Vars, Choicecount) :-
+eval_and_print(Goal, Vars0, Choicecount) :-
user:call(Goal),
+ rewrite_equations(Vars0, Vars),
abolish(found_a_solution/0),
asserta(found_a_solution :- !),
'$choicestack_size'(ChoicecountNew),
@@ -58,6 +59,26 @@ eval_and_print(Goal, _, _) :-
write('false.'),
nl.
+rewrite_equations(Eqs0, Eqs) :-
+ apply_bindings(Eqs0),
+ remove_identities(Eqs0, Eqs).
+
+apply_bindings([]).
+apply_bindings([A = B|Rest]) :-
+ ( var(B)
+ -> call(B = A)
+ ; true
+ ),
+ apply_bindings(Rest).
+
+remove_identities([], []).
+remove_identities([A = B|Rest0], Result) :-
+ remove_identities(Rest0, Rest),
+ ( A == B
+ -> Result = Rest
+ ; Result = [A = B|Rest]
+ ).
+
write_state(end) :- write('.'), nl.
write_state(more).
@@ -68,7 +89,7 @@ write_bindings([]).
write_bindings([Var = Val|Bs]) :-
write(Var),
write(' = '),
- writeq(Val),
+ write(Val),
( Bs = []
-> true
; put_char(','), nl