How would I write a two clause recursive definition to find the maximum value in a list. So far I have written this:
max(L,M):-
max([H|T],M):-
max(T,H,M).
max([],M,M).
max([H|T],Y,M):-
H =< Y,
max(T,Y,M).
max([H|T],Y,M):-
H > Y,
max(T,H,M).
This doesn't work, it says there is a syntax error which I can't quite see, and I know it isn't two clause either. Anyone know how I could simplify it to make it two clause?
This one works for sure
I know this question is old, but here's an answer using the if-then-else construct: