0
votes

So I wrote this Facts in test.pl file:

bottle(b1).
bottle(b2).
bottle(b3).
bottle(b4).

full(b1,100).
full(b2,750).
full(b3,500).
full(b4,250).
consume(X, Y). :-full(X,Z);Z>=Y.

The last line in words: It should return true if the Y Parameter of consume is less then the bottle has if it is full. But if I query this function I get always as a result true. I'm new to Prolog so it would be kindly if you could explain why the error is appearing and Point me in the right direction how to solve this error.

1
You should have received plenty of warnings about "singleton variables" that you chose to ignore. - false
Mind that Prolog does not use functions, these are predicates, that's an important aspect. - Willem Van Onsem
@false Yep indeed I did - Matthias Herrmann
@false why do I receive there a error? consume(bottle(X),Y) :- full(bottle(X),Z);Z<=Y. - Matthias Herrmann
Substitute <= by =< - false

1 Answers

0
votes

A stray dot.

% original
consume(X, Y). :-full(X,Z);Z>=Y.
% modified
consume(X, Y) :-full(X,Z);Z>=Y.

Please note that this fixes only the "always true" problem.