Error Undefined Procedure in Prolog

2020-04-11 02:26发布

问题:

I wrote a rule:

parent(georgie,jessy) :-
   child(jessy,georgio).

but, when I want to prove

?- parent(georgie,jessy).

I get an error:

parent/2: Undefined procedure: child/2

Please help. Thanks.

回答1:

Define the child relationship:

child(jessy, georgie).

Define the parent relationship to be opposite to the child relationship:

parent(X, Y) :- child(Y, X).

And test it.

?- parent(georgie, jessy).
true.


标签: prolog