Re: Missing in misc.e
- Posted by Jason Gade <jaygade at yahoo??om> Jul 20, 2007
- 693 views
CChris wrote: > > Not elegant, as the curly braces are not needed. > Confusing, because the min() notation to compare two objects is so universal. > > If we could overload symbols, ie having different routines share the same name > with different signatures, because they do the same thing to different sorts > or forms of arguments, then both might be called min() or max() for more > convenience. > But I doubt this will be ever possible in Eu because it is weakly typed. > > CChris I still think it's elegant. Why have two functions that do the exact same thing? In fact, I'd write it to return an index as well:
global function min(sequence s) object x integer index x = s[1] for i = 2 to length(s) do if x > s[i] then x = s[i] index = i end if end for return {x, index} -- depending on what is of more interest this order could be swapped end function
Implement max() similarly or use one function with a flag value as you did somewhere up above. Personally, I prefer weak-typing. -- "Any programming problem can be solved by adding a level of indirection." --anonymous "Any performance problem can be solved by removing a level of indirection." --M. Haertel "Premature optimization is the root of all evil in programming." --C.A.R. Hoare j.