I have a problem in the derivation tree of finding the maximum of a given number list. How variables are assigned.?
Following are the rules in Prolog
max([X],X). %If one element list, the element is the maximum
max([X|L],X) :- max(L,M), X > M. %If head is greater than the maximum of tail the head is the maximum.
max([X|L],M) :- max(L,M), X =< M. %If head is less than or equal the maximum of tail, then maximum of tail is the maximum.
So I want to know the steps for how Prolog answer the following query.
?- max([10,20,30], M).
Please give me an idea, how recursive calls work and variables are assigned.
Thank you...