What is a singleton variable in prolog?

2

I'm doing a job in Prolog and when trying to make a query it says there are "Singleton variables". For example, a part of the code:

s([Policia_X, Policia_Y, Ladrao_X, Ladrao_Y]) :- pode_andar_horizontal([Policia_X, Policia_Y]).

Returns the error:

  

Warning: c: /users/leila/desktop/2018.2/ia/ia/trab1.pl: 35:           Singleton variables: [Ladrao_X, Ladrao_Y]

What does this mean?

    
asked by anonymous 25.10.2018 / 03:00

1 answer

1

This is a warning to help you with two common errors:

  • Spelling errors in variables
  • A variable that is not being used

So in your specific case, this warning says that in the trab1.pl file, on the 35 (which is :35 ) line, you may be using variables that were no longer used in this rule or fact. It can also mean a misspelling. In case, to use the variable only once, for example:

teste(A): - t(B, A).

In this case, you can get rid of the warning message by putting (_) in front of the variable singleton , in this case the variable B :

teste(A): - t(_B, A).
    
27.10.2018 / 22:13