Looking at the new code for max_member/2:
max_member(Max, [H|T]) :-
max_member_(T, H, Max).
max_member_([], Max0, Max) =>
Max = Max0.
max_member_([H|T], Max0, Max) =>
( H @=< Max0
-> max_member_(T, Max0, Max)
; max_member_(T, H, Max)
).
I’m wondering about writing it like this:
max_member_([], Max0, Max) =>
Max = Max0.
max_member_([H|T], Max0, Max), H @=< Max0 =>
max_member_(T, Max0, Max).
max_m_([H|T], _Max0, Max) =>
max_member_(T, H, Max).
and if the two cases of [H|T]
bother you:
max_member_([], Max0, Max) =>
Max = Max0.
max_member__([H|T], Max0, Max) =>
max_member__(H, T, Max0, Max).
max_member__(H, T, Max0, Max), H @=< Max0 =>
max_member_(T, Max0, Max).
max_member__(H, T, _Max0, Max) =>
max_member_(T, H, Max).
All of these raise an exception if they’re not given a proper list.
Also, how well does =>
play with lazy lists? (In the particular case of max_member/2, the older definition works with a lazy list, whereas the new definition throws an error.)