% max(L, M) computes as M the maximum of a non-empty list of numbers L. max([X | L], M) :- max_helper(L, X, M). max_helper([], M, M). max_helper([X | L], M, N) :- X > M, max_helper(L, X, N). max_helper([X | L], M, N) :- X =< M, max_helper(L, M, N). test :- max([3, 7, 2, 9, 1, -5], M), write(M), nl.