% max(L, M, I) computes as M the maximum of a non-empty list of numbers L, with % I as the first index of M in the list, starting with index 0. max([X | L], M, I) :- max_helper(L, 1, X, 0, M, I). max_helper([], _, N, I, N, I). max_helper([X | L], J, N, _K, M, I) :- X > N, J1 is J+1, max_helper(L, J1, X, J, M, I). max_helper([X | L], J, N, K, M, I) :- X =< N, J1 is J+1, max_helper(L, J1, N, K, M, I). test :- max([3, 7, 2, 9, 1, -5], M, I), write(M), write(' at '), write(I), nl.