The anonymous variable

The name of every anonymous variable is _ .

The anonymous variable is an element of Prolog that is similar to a variable in almost every way. As presumable, all the occurrences of the name of an ordinary variable stand for the same variable within one clause. On the contrary, every occurrence of _denotes a distinct variable .

Example:

?- X=[_,_], X=[a,b], write(X).

will succeed, even though the two occurrences of _ seem to dictate instantiating _ to distinct terms. The output of write will be

[a,b]

Some of the use of the anonymous variable is to fill in places, where anything is welcome , not burdening the mind of the Prolog programmer with an otherwise useless name for an ordinary variable. Sometimes, when the term welcome is also irrelevant, the anonymous variable is also the best choice, because the collection of anonymous variables resembles a single one that is 'immune to instantiation'.