Non-tabled Predicates

If you use KB updates (Knowledge Base Updates), or certain other operators (basically the ones followed by curly brackets) in a rule body, such as:

p(?x) :- t_insert{?x}.

Flora will give you a warning like:

++Warning[Flora-2]> [tmp$user.flr] <Dependency check>
                  non-transactional predicate or method in a rule that starts with
p(?A)@\@ near line(1)/char(1)  depends on db operation
t_insert$_$ctxt(?A,?B,?C)@\prolog near line(1)/char(10) in [tmp$user.flr]

What Flora is trying to tell you is the following. Normal predicates and properties in Flora are “tabled”. Tabling basically means that previous reasoning results for a predicate are remembered (“tabled”), and later queries involving the same results do not need to repeat the same reasoning; the results can be looked up in the “table”.

Therefore, when you use certain features that have side-effects (e.g., KB updates), you cannot count on those side effects taking place if they occur under a tabled predicate. We call these features “procedural”. To continue with the example above, suppose we issue the following queries, in the given order:

?- p(foo).         // foo is now true
?- delete{foo}.    // foo is now false, but p(foo) is tabled.
?- p(foo).         // p(foo) is looked up in the table
?- foo.            // fails, because the rule was not executed the second time

The inline comments indicate the problem. When a goal is already tabled, its rule, along with any side effects, will not be executed.

To remedy this (and get rid of the warning in the process), we have to mark the predicate as “non-tabled”. This is done by adding a % in front of the name, i.e.,

%p(?x) :- t_insert{?x}.

The next problem is that using %p in a rule body where the rule head is non-tabled will now produce the same warning as above. In other words, “proceduralness” propagates through rules. For this reason, we recommend that you avoid using procedural features other than in a few specialized places. Do not embed them deeply in your rule system and simply mark everything as procedural, as this would void many of the advantages of Flora.