Re: Missing in misc.e
Jason Gade wrote:
> how is the language supposed to grow at all?
Put the new code in say minmax.e instead. Far as I know there is no law
stating that we cannot have more than 13 files in Euphoria/include.
CChris, some suggestions for you (untested):
constant FMM_MIN = 2, -- look for min, so do compare()=-1 \ Picked so that
"1-and_bits(mode,2)"
FMM_MAX = 0, -- look for max, so do compare()=+1 / gives us the -1 or +1 we
need.
FMM_IDX = 0, -- return idx as result
FMM_VAL = 1 -- return value as result
constant
FMM_MINIDX = FMM_MIN + FMM_IDX,
FMM_MINVAL = FMM_MIN + FMM_VAL,
FMM_MAXIDX = FMM_MAX + FMM_IDX,
FMM_MAXVAL = FMM_MAX + FMM_VAL
type nonmts(object s)
if sequence(s) then
if length(s) then return 1 end if
end if
return 0
end type
function find_minmax(sequence s, integer mode)
--
-- locates the largest or smallest value in s.
-- s must be a non-empty sequence.
-- mode should be one of FMM_MINIDX, FMM_MINVAL, FMM_MAXIDX, or FMM_MAXVAL
-- (see find_min/find_max/get_min/get_max)
-- eg:
-- k = find_minmax(s1,FMM_MINIDX)
-- v = find_minmax(s1,FMM_MAXVAL)
--
integer comparecode, result_idx
object result_val, this
comparecode = 1-and_bits(mode,FMM_MIN)
-- ie:
-- if and_bits(mode,FMM_MIN) then
-- comparecode = -1
-- else
-- comparecode = +1
-- end if
result_val=s[1]
result_idx=1
for i=2 to length(s) do
this=s[i]
if compare(this,result_val)=comparecode then
result_val=this
result_idx=i
end if
end for
if and_bits(mode,FMM_VAL) then
return result_val
else
return result_idx
end if
end function
global function find_min(nonmts s)
-- returns the index of smallest value in s.
-- s must be a non-empty sequence.
return find_minmax(s,FMM_MINIDX)
end function
global function find_max(nonmts s)
-- returns the index of largest value in s.
-- s must be a non-empty sequence.
return find_minmax(s,FMM_MAXIDX)
end function
global function get_min(nonmts s)
-- returns the smallest value in s.
-- s must be a non-empty sequence.
return find_minmax(s,FMM_MINVAL)
end function
global function get_max(nonmts s)
-- returns the largest value in s.
-- s must be a non-empty sequence.
return find_minmax(s,FMM_MAXVAL)
end function
I don't know what an ibject is, and there is no point in adding min and max
functions to this file, unless you make them global ;-P.
Regards,
Pete
|
Not Categorized, Please Help
|
|