Task

Create a function that returns the maximum value in a provided set of values,

where the number of values may not be known until run-time.




list_max = fn ([Head:Rest]) {
  list_max(Rest, Head)
}
 
list_max = fn ([], Res) {
  Res
} 
fn ([Head:Rest], Max) when Head > Max {
  list_max(Rest, Head)
} 
fn ([_Head:Rest], Max) {
  list_max(Rest, Max)
}
 
list_max1 = fn ([H:T]) {
  lists.foldl(fn erlang.max:2, H, T)
}
 
@public
run = fn () {
    io.format("~p~n", [list_max([9, 4, 3, 8, 5])])
    io.format("~p~n", [list_max1([9, 4, 3, 8, 5])])
}
 