| Dirk Mittler 2004-05-16, 10:31 pm |
| I looked at the definition of duplicate_term/2 more carefully. Before, I
expected that copy_term/2 would copy "and unify" as stated in he manual, but
that duplicate_term/2 would only duplicate, not unify.
However, since duplicate_term/2 is supposed to do everything the more
standard copy_term predicate does, it should follow that duplicate_term will
also unify.
For that reason, this code will also 'work' , or have the same effect. I've
tested it:
lousy_attrib(X) :-
freeze(X, fail).
consistent(X) :- nonvar(X),
duplicate_term(X, _Temp).
% copy_term(X, Temp).
consistent(X) :- var(X),
duplicate_term(X, Temp),
copy_term(1, Temp).
consistent_l(L) :- is_list(L),
length(L, N),
consistent_l(L, N).
consistent_l(L) :- \+ is_list(L),
consistent(L).
consistent_l(_L,0).
consistent_l(L, N) :-
nth1(N, L, E),
consistent_l(E),
N2 is N - 1,
consistent_l(L, N2).
consistent_e(E) :- nonvar(E),
E =.. L,
consistent_l(L).
consistent_e(E) :- var(E),
consistent(E).
"bart demoen" <bmd@cs.kuleuven.ac.be> wrote in message
news:1084303534.868677@seven.kulnet.kuleuven.ac.be...
[...]
Remember, the attributed goals could further be
lousy_attrib(X) :-
freeze(X, (X = 1, X = 2.)).
In this case, if X has no initial value, the test must also fail.
It seems unlikely that CHR interpretation would produce he following
attribute, but in case it does, it should succeed:
lousy_attrib(X) :-
freeze(X, (X is 5, X = 5.)).
I would suspect that variables other than the one the attributed goal
belongs to could arise from constraint definitions, which *might* equate
them to each other as well when the same variable recurs in multiple
instances of the same constraint.. The purpose then wouldn't simply be
either, to test for the simple equality to a constant.
But my consideration, that I might base the relatively straightforward
constraint definitions on unreliable, complex Prolog, instead of the other
way around, may still not be very useful.
If I make my constraint
rel(A, B) ==> consistent_l([A, B]).
then my constraint would immediately fail, due to incomplete A or B , if
added goals are not always supposed narrow it.
So I might plan to put my reusable predicate like this,
rel(A, B) <== unreliable_prolog(A, B), consistent_l([A, B]).
for only the suspect Prolog predicate's clause. And even such a plan is
ephemeral, until I've received Ivan Bratko's book "Prolog Programming For
Artificial Intelligence" from Amazon.com , and learned more about it.
Dirk
|