1
votes

I'm just beginning to learn Prolog and I am using SWI-Prolog on Ubuntu. I'm watching a YouTube tutorial on Prolog where a query returns (infinite) correct answers, but on my computer the same query only returns one seemingly random answer.


Code: vertical(line(point(X, Y), point(X, Y2))).

Query: vertical(line(point(5, 10), X)).

Expected tutorial output: X = point(5, _ ).

Actual output: X = point(5,6058).


For a point X to be vertical with (5,10) it needs to have the form (5, _ ), but my output is (5,6058). The output is also different for the same command the second time I run the query, and then it stays the same.

1

1 Answers

1
votes

It is a free variable. If we query this, we obtain:

?- vertical(line(point(5, 10), X)).
X = point(5, _3730).

Notice the underscore in _3730. That means that it is a variable. If you introduce a free variable, a Prolog interpreter will add a number to this. This is useful if there are multiple free variables, since it makes it clear which variables are the same, and which variables are different ones.