// A generic 'Max' and 'Min' function taking an arbitrary number of arguments
// of any type with a less-than operation
// Condition for a type to be 'ordered': being able to write A < B
generic type ordered if
with ordered A, B
with boolean Test := A < B
// The Max and Min of a list with one element are that element
function Max(ordered X) return ordered is
return X
function Min(ordered X) return ordered is
return X
// The Max and Min with more than one argument are created from
// the Max and Min with one less argument
// 'result' is the implicitly declared result of a function
function Max(ordered X; other) return ordered is
result := Max(other)
if result < X then result := X
function Min(ordered X; other) return ordered is
result := Min(other)
if X < result then result := X
// Examples of use
procedure Test() is
with real R := Max(1.0, 3.0, 5.0)
with integer I := Min(1, 3, 4, 5, 6, -1)