%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TP1 Exo1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Version 1 : use a procedure
declare Max in
proc {Max L Result}
case L of
nil then Result=0
[] H|R then
local X in
{Max R X}
if H > X then Result=H else Result=X end
end
end
end
local Z in
{Max [4 7 17 42 26] Z}
{Browse Z}
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Version 2 : use a function
declare
fun {Max L}
case L of
nil then 0
[] H|R then
local MR = {Max R} in
if H > MR then H else MR end
end
end
end
{Browse {Max [34 78 4 256]}}