Prolog: predicate for maximum without accumulator
Is it possible to create a predicate max/2 without an accumulator so that max(List, Max) is true if and only if Max is the maximum value of List (a list of integers)? Willem Van Onsem Yes, you can calculate the maximum after the recursive step. Like: max([M],M). % the maximum of a list with one element is that element. max([H|T],M) :- max(T,M1), % first calculate the maximum of the tail. M is max(H,M1). % then calculate the real maximum as the max of % head an the maximum of the tail. This predicate will work on floating points for instance. Nevertheless it is better to use an accumulator