1. Optimized type check
To avoid errors with bad is simple.
Instead of using type check use a function to
modify the input to be correct.
Example:
type hours(integer h)
if h > 23 then
return 0
elsif h < 0 then
return 0
else
return 1
end if
end type
hours h
h = 24 -- gives error
---------------------------------
function force_hours(object h)
if sequence(h) then--is it a number or sequence
--assume it is a string EXAMPLE "12" not {1, 2}
h = value(h)--make it a number
end if
h = floor(h)--strip decimals
if h > 23 then--if above 23 then make it 23
h = 23
elsif h < 0 then--if below 0 then make it 0
h = 0
end if
return h
end function
integer h
atom a_h
integer i_h
sequence s_h
a_h = 23.125
i_h = -1
s_h = "15"
h = force_hours(a_h)--h now equals 23
h = force_hours(i_h)--h now equals 0
h = force_hours(s_h)--h now equals 15
I believe that errors produced by type_check
can be found in a created ex.err
--Lucius Lamar Hilley III
-- E-mail at luciuslhilleyiii at juno.com
-- I support transferring of files less than 60K.
-- I can Decode both UU and Base64 format.