laurelang
laurelang copied to clipboard
Feature: smart context query reorderer
Consider a predicate flatten non trivial:
: ?flatten_nt(int[][]) -> int[].
?flatten_nt([]) -> [].
?flatten_nt([x]) -> x.
?flatten_nt(array) -> flattened {
flattened = append<int>(x, y);
y = flatten_nt(t);
linked(x, t) = array;
}
Predicate will fail if we try to instantiate array from flattened:
?- flatten_nt(x) = [1,2,3]
* too broad error *
to change this behaviour queries should be reordered
?flatten_nt(array) -> flattened {
linked(x, t) = array;
y = flatten_nt(t);
flattened = append<int>(x, y);
}
the idea is to do that automatically
qcontext may have order field (a vector with order calculated on scope entering)
[2, 1, 0]
Reorderings for each case can be generated during predfinal generation. (Body linking for each arguments I/U permutation)
there is a room for improvement in adding support for unify, unify all, quantor statements