1
votes

Can anyone help me out with Prolog recursive functions?

I have to type in a recursive input and it should give me true, but it gives me an error and I sitll don´t know how to figure it out

Bob(Food(X)):- Bob(X).
Bob(eat(X)):- Bob(X).
Bob(yummy(X)).

Is what I have and Input Food(Food(eat(yummy)))should result in true

But I get an Error: Unknown procedure: Food/1 (DWIM could not correct goal) this is basically the whole story.

1
Your program does not mention any Food predicate. Furthermore predicates start with a lowercase, so bob, not Bob... - Willem Van Onsem
The last clause should also be yummy. - Willem Van Onsem
Apoligies.Everything is written small :D, but how would I define the Food predicate properly? - NintyNinerQuery
So instea of bob(yummy(X)). bob(yummy) ? - NintyNinerQuery

1 Answers

0
votes

predicates, functors and constants start with a lowercase. Your yummy is also a constant, so there is no (X) part here. The predicate should thus look like:

bob(yummy).
bob(food(X)):-
    bob(X).
bob(eat(X)):-
    bob(X).

This then gives us a:

?- bob(food(food(eat(yummy)))).
true.