Just add a new variable name to your clause. When reading left-to-right, a new variable name indicates a "fresh variable" that is "as yet unbound" / "so far uninstantiated".
No need to declare a variable explicity. They are just names for places selected from an infinite (or at least RAM-sized) sea of places. For example
foo(X) :- bar(X,Y),baz(Y,X).
^
|
You needed a new variable, you now have it.
A "fresh variable" named Y
has been added to the set of variables used in this clause by naming it in the call to bar(X,Y)
.
In particular, the variable name _
can be used to name fresh variables without inventing new names. Any variable named _
is different from all other variables
X=[_,_,_,_,_].
You created 5 fresh variables by naming them _
. Note that X
is initially also a fresh variable but then gets unified with the (tip of) the 5-element list.
When printing, SWI Prolog gives uninstantiated variables unique names derived from the position in some internal datastructure:
?- X=[_,_,_,_,_].
X = [_6480,_6486,_6492,_6498,_6504].