1. min(), max()
- Posted by Lucius Hilley <lhilley at CDC.NET> Jun 27, 1999
- 399 views
- Last edited Jun 28, 1999
Before reading the previous messages I had never considered min() or max() as being used in the following form. global function min(object input, atom minvalue) object output output = (minvalue <= input) output = input * output return output end function My suggestion is for min() to return the value of the smallest atom in a sequence. The above routine should be named as at_least() and its compliment would be at_most(). My previous proposal for min() falls short of handling embedded sequences. It only handles 1D sequences. Handling emedded isn't a big deal and the code is below. global function at_least(object input, atom least) return (input * (input >= least)) end function global function at_most(object input, atom most) return (input * (most >= input)) end function global function min(sequence input) atom smallest, temp if atom(input[1]) then smallest = input[1] else smallest = min(input[1]) end if for A = 2 to length(input) do if atom(input[A]) then temp = input[A] else temp = min(input[A]) end if if smallest > temp then smallest = temp end if end for return smallest end function global function max(sequence input) atom largest, temp if atom(input[1]) then largest = input[1] else largest = max(input[1]) end if for A = 2 to length(input) do if atom(input[A]) then temp = input[A] else temp = max(input[A]) end if if temp > largest then largest = temp end if end for return largest end function Lucius L. Hilley III lhilley at cdc.net +----------+--------------+--------------+ | Hollow | ICQ: 9638898 | AIM: LLHIII | | Horse +--------------+--------------+ | Software | http://www.cdc.net/~lhilley | +----------+-----------------------------+