say tree is some algebraic tree type. When comparing two variables of type tree, it makes sense to first check whether the variables point to the same address in memory. Because in case they do, we know that they are equal and we can spare the much more costly comparison of the variables' values.
To make address-equality checks work out most often, we should write our programs as confluent as possible. I.e., when we known that a predicate's output equals one of its inputs, it is a good idea to let the output variable point to the same memory address as the input variable (instead of returning a duplicate of the input variable's value residing at a different address in memory).
However VIP (7.5.0.2) does not support the 'confluence dogma' very well. Please have a look at this example. It has two predicates test1 and test2 which are just handing the input over to the output. After calling these predicates the example checks whether in- and output variables point to same memory address. Surprisingly (at least for me) the result is that in- and output do not point to same address. Why is that, could it be improved in future?
Code: Select all
domains
tree =
empty;
node(tree LeftChild, tree RightChild).
class predicates
test1 : (tree) -> tree.
clauses
test1(Tree) = Tree.
class predicates
test2 : (tree, tree [out]).
clauses
test2(Tree, Tree).
clauses
run() :-
Input = node(empty, empty),
Output1 = test1(Input),
test2(Input, Output2),
stdIO::write(toBoolean(uncheckedConvert(pointer, Input) = uncheckedConvert(pointer, Output1)), '\n'),
stdIO::write(toBoolean(uncheckedConvert(pointer, Input) = uncheckedConvert(pointer, Output2)), '\n').