Search code examples
prolog

Error Undefined Procedure in Prolog


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.


Solution

  • 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.