I’m going through the book Programming for Artificial Intelligence by Ivan Bratko, I’m stuck on a basic problem and running into an error and the previous answers on stack overflow don’t seem to be helping.
I’m stuck trying to write a rule using a previous fact as an argument and getting the error
Single variables: [Y]
the code I’m trying to run is this
parent(myfather,me).
parent(mymother,me).
happy(X) :-
parent(X,Y).
I’ve managed to make rules like this in the past and I think i’m just missing something very obvious as to why this isn’t working. I think that when this compiles and I run
happy(myfather).
It will return true as it will replace X in the happy rule with myfather, then check parent(X,Y) with parent(myfather,Y). and try to then see if there is a fact that says parent(myfather,somethingelse….).
I’m also using swipl on macOS if that is relevant, thanks.
EDIT:
I hadn’t checked but the program actaully works as it should but still gives the warning, it makes sense however is there any way of getting rid of the error or an understanding of why the error is there?
2
Answers
Singleton variables is a warning, not an error.
It is meant to remind you that you have a named variable occurring only once within a rule.
If you want to suppress the warning for that particular variable, rename it to a name beginning with underscore (e.g.
_Y
), e.g.:or rename it to
_
(anonymous variable), e.g.:This type of warning is very useful for spotting typos, such a mistyped variable name:
or other kind of typos, such as a period typed in place of a comma:
or other logical errors.
Without the singleton variable warning, these errors would go unnoticed and would be more difficult to track down.
So, seeing this warning usually rings a bell for looking for other type of errors as well. If there are no other errors, then just fix the singleton variable by making it anonymous.
If you know what you are doing, you can globally disable the warning with:
I know this is an old question, but i get the solution for that, if you got
Singleton variables: [Y]
error message, please check yourcode
and yourQueries
is it mixed with upper-case, lower-case or not. Because Prolog is case sensitive.