Вопрос

I know this is kinda stupid question, but I am really despaired now, because I cant find the way to build it. I always get this error

ERROR: call/2: Undefined procedure: main/1
ERROR:   However, there are definitions for:
ERROR:         main/0

Even though I tried

father(ahmad,samer).
father(ahmad,lolo).
father(ahmad,koko).


grandfather(X,Y):-
    father(U,X),
    father(Y,U).

main :- father(ahmad, X), writef('%t\n', [X]).

So can someone help me to do it the right way ?

Это было полезно?

Решение

Works just fine for me.

Just type main. Don't forget the .,otherwise it won't run. Here is what I got

2 ?- main.
samer
true ;
lolo
true ;
koko
true.

After true type ; instead of pressing the Enter button if you want to show all three names. If you press Enter, only the first name will appear.

From your code I figured out that ahmad is the father,so about the grandfather query, I think I has to be this way:

granfather(X,Y):- father(X,U),father(U,Y).

Because on your father query the father is on the left

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top