I'm working through the first problem in a famous collection of 99 Prolog problems. Here is the question:
Find the last element of a list. Example: ?- my_last(X,[a,b,c,d]). X = d
and here is my file of facts and rules:
my_last(_, []).
my_last(_, [H | T]) :- my_last(H, T).
and my query:
my_last(X, [a,b,c,d]).
My output is true, but I want my output to be the value of the variable X when the computer gets to the point that evaluates to true. I used trace, and I think the program works much as I expected it to. Basically, it runs through my_last(a, [b, c, d]) and so on until my_last(d, []), then evaluates to true and starts backing out of the recursion. But it still only evaluates to true! Why is this happening? Is it because I have variables in my facts/rules?