Reputation: 33
I am completely new to Prolog and self teaching out of interest. Very sorry to bring such a basic question to you, but the Manuals (SWI-Prolog) don't seem to clarify why I see this behaviour.
I am playing around with basic predicates with multiple values and try to query for all predicates that would be valid answres. SWI-Prolog finds the first valid predicate only and then stops, I am unsure if this is due to me using predicates instead of lists or if this is an expected behaviour of Prolog.
% list of predicates , i.e items in a shop with aisle, brand & value
item(2,charmin,8).
item(4,nestle,9).
item(1,barilla,4).
item(3,nestle,5).
% query to find all items of a Brand
item_brand(Brand):-
item(_Aisle,Brand,_Cost).
If issuing a query like item_Brand(barilla) I get the expected return of item(1,barilla,4). But if searching for item_Brand(nestle), Prolog only returns the item(4,nestle,9) result and stops instead of also finding item(3,nestle,5).
I have tried to seperate the Variable in the rule and make it a comparison against the atom of the predicate, but I am either getting the same result or creating infinite loops with my attempts so far.
Even if you could just provide a pointer to some Manuals or learning materials I would much appreciate it.
Upvotes: 2
Views: 314
Reputation: 10102
This has more to do with the top level you are using. Current systems (including SWI) present the first answer and then await for ;
to produce the next one. Some older top levels did not ask for further solutions if there are no variables in the query.
?- item_brand(nestle).
true
; true.
So there is one solution and one redundant solution.
Upvotes: 2