Backtracking in the presence of non-logical variables
In the presence of non-logical variables mutual exclusion is
needed for reasons of protection.
Mutual exclusion takes effect whenever an answer statement
is encountered.
This protection however lasts only until the first answer
substitution is requested and received by a resumption goal.
This procedure is motivated by the assumption that any important
change of the state of the object can be done during the period that
the first solution is produced.
Backtracking over the second and remaining solutions can be done
while other processes are active.
The example that follows shows how the state of an object
can be fixed by binding it to a logical variable.
object data {
use lib.
var d = [1,2,3].
data():- answer(any), data().
update(L):- L1 = val(d), append(L1,L,R), val(d) = R.
query(X):- L = val(d), member(X,L).
}
The clause for query shows
that backtracking occurs over the list stored in
d at the time the evaluation of d is started.
Since mutual exclusion is provided by the constructor for data
no intermediate updating can take place.
Suppose however that we have a predicate
that binds
the N-th element of L to X, and that query is defined as
query(X):- L = val(d), position(1,X,L).
query(X):- L = val(d), position(2,X,L).
etcetera
then another process may update the variable d while a
process is still backtracking over query, thus
dynamically influencing the outcome.