I'm trying to understand this sum predicate
sum([], 0).
sum([H|T], Sum) :-
sum(T, Temp),
Sum is Temp + H.
It works however I don't understand why. From my understanding with a query such as sum([1,2,3], Sum) it will match on the second clause instantiating H as 1 and T as [2,3] and Sum is still Sum. Then it will attempt to satisfy the first sub goal calling sum again but in the second goal where Sum is Temp + H when is Temp given a value?