If you want to be precise in talking about Prolog, it's necessary to distinguish between (at least) answers and solutions to a query. An answer is a procedural notion, it is a substitution of variables produced by Prolog every time a query succeeds. A solution is a substitution of variables under which a query succeeds. Every answer substitution is a solution, but this does not make these notions synonymous.
Consider this predicate:
foo(a).
foo(a).
This has two answers (which happen to look the same):
?- foo(X).
X = a ;
X = a.
It has a single solution: Only the substitution X = a
makes it succeed, and Prolog can even prove this:
?- X = a, foo(X).
X = a ;
X = a.
?- dif(X, a), foo(X).
false.
In this case there were more answers than solutions. The opposite is also possible:
bar(f(_X)).
Here the query bar(T)
has a single answer, but more than one solution (in fact, infinitely many):
?- bar(T).
T = f(_708).
?- T = f(1), bar(T).
T = f(1).
?- T = f(2), bar(T).
T = f(2).
So now let's look at the first query from the question:
?- append([a, b, c, d], Y, Z).
Z = [a, b, c, d|Y].
With the definitions from above, this has a single answer. But as you point out, we can substitute infinitely many different values for the variables, getting infinitely many solutions, for example:
?- Y = [1], append([a, b, c, d], Y, Z).
Y = [1],
Z = [a, b, c, d, 1].
?- Y = [1, 2], append([a, b, c, d], Y, Z).
Y = [1, 2],
Z = [a, b, c, d, 1, 2].
Now, the bad news is that your teacher doesn't seem to be using the same convention as I am using here. Using the terms defined above, the teacher was asking about answers, while you are thinking in terms of solutions. It would be interesting to know if they understand this distinction, and what terms they use for these distinct notions. If they really meant answers, then they are correct that this query does not have infinitely many. If they really meant solutions, then you are correct that it does have infinitely many of those.
As for the second query:
?- append(X, Y, X).
X = Y, Y = [] ;
X = [_818],
Y = [] ;
X = [_818, _824],
Y = [] ;
X = [_818, _824, _830],
Y = [] .
You're right that Y
can only be []
, but that still leaves an infinite number of solutions for X
. And here Prolog also produces infinitely many answers describing those solutions.