To expand on the matter: you can name your variables, in swi at least, with a starting _
to indicate that they won't be used more than once. This way you can still add a meaningful name to a variable and preserve a valuable information. Here is an example with member/2
:
member(Element, [Element|Tail]).
member(Element, [Head|Tail]) :-
member(Element, Tail).
would produce warnings, but
member(Element, [Element|_Tail]).
member(Element, [_Head|Tail]) :-
member(Element, Tail).
would not, yet you have preserved all the information contained in your variables names.
Though, you have to note that a variable starting with a _
isn't the same thing that the anonymous variable, for example, in this code (which is kinda useless):
member(_, _).
the two _
are different variables, while in this code:
member(_A, _A).
the two _A
are the same variable.