Ordering of Goals

The operational semantics of Flora means that the ordering of terms within a rule body can matter, in two respects. First, the ordering of goals in a rule can affect computational efficiency. For example, suppose you have a rule

p(?x) :- q(?x), ?x < 10.

and q(?x) performs some very long computation. Now, when we execute a query like p(11), the very long computation of q(11) will be performed, before we finally fail due to the condition ?x < 10. If, instead, we put the inequality first, we can quickly filter out such goals and save a lot of computational effort.

Secondly, sometimes we have to make sure that variables are instantiated before we attempt certain operations on them. For example, suppose we want to execute queries like p(?x), using the rule above. Now we cannot put the inequality first in the rule body, because Flora cannot evaluate inequalities involving variables [1]. So we have to execute the goal q(?x) first, and make sure that it instantiates the variable.

Everything said here also applies to ordering of goals in queries.

[1]An exception to this is CLPR, see CLP(R) math