Prologs with Occurs Check constantly on?
- From: Jan Burse <janburse@xxxxxxxxxxx>
- Date: Sun, 09 Oct 2011 19:05:34 +0200
Are there any Prologs with Occurs Check
Looking at some program examples and
oportunities that are present when code
is generated. I have the feeling that
Prologs with Occurs Check on should run
in similar time as Prologs with Occurs
Despite the theoretical limitations to
make it fast and despite the known
For example if I look at append/3:
append([X|Y],Z,[X|T]) :- append(Y,Z,T).
I generate the following trivial code:
append(, X, X).
1 unify_atomic _0, 
2 unify_term _1, _2
append([X | Y], Z, [X | T]) :-
append(Y, Z, T).
3 unify_compound _0, [X | Y]
4 unify_compound _2, [X | T]
5 unify_var _1, Z
6 last_goal append(Y, Z, T)
For occurs check constantly on, I would
only need to replace the following lines:
2' unify_term_with_occurs_check _1, _2
4' unify_compound_with_occurs_check _2, [X | T]
So the code already reduced the number
of needed unification with occurs checks.
4' could profit from unraveling the unification
and we would end up with:
4'' unify_term_with_occurs_check _2', _0'
But question is whether the two remaining
unify_term_with_occurs_check could be further
speed up with some runtime annotations
in the terms.
I have the feeling something could be done
with a ref count annotation. If Var has
ref count=0, then checking Var occurs in Term
is futil. Unfortunately all my Vars have
initially ref count=1.