I have started using Prolog and I am having this problem with a dynamic predicate - I don't get the right result.
This is my database:
:- dynamic mother/2.
mother(X,Y).
grandemother(X,Y) :-
mother(X,A),
mother(A,Y).
These are some of the results I get:
1 ?- assert(mother(alice,lise)).
true.
2 ?- assert(mother(lise,kate)).
true.
3 ?- grandemother(alice,X). % should only give X = kate.
true ;
X = lise ;
X = kate ;
true ;
X = kate.
4 ?- grandemother(alice,lise). % should only give false.
true ;
true ;
true ;
false.
5 ?- grandemother(X,kate). % should only give X = alice.
true ;
true ;
X = alice ;
X = alice ;
X = lise.
I really don't know where the problem is, any ideas?
mother(X, Y).? That is stating thatXis the mother ofYno matter whatXandYare since they're variables. - lurkermother (alice,lise),..etc , but i wanted to do the instantiation using the assert predicate . - StamDadmother(X, Y)., the line right after yourdynamic/1call. That's a "fact" that says anyone is the mother of anyone else. - lurker