Re: Source changes
Alan Oxley wrote:
>
> Derek wrote ..
> This set will attempt to convert the text to the requested format, but if
> they are unable to they do not fail, instead they return zero.
>
> Derek, how about always returning a sequence with the first atom being
> the return code? Otherwise I would not know the difference if the data to
> be evaluated resolved to zero, and a function failure.
I've catered for this too in that all the 'to_xxx' routines will have an
equivalent 'conv_xxx' routine. The 'to_xxx' is designed to always return a number
because there are situations in which this is acceptable to do, and the
'conv_xxx' returns a sequence if it fails and a number if it succeeds.
The usage of 'conv_xxx' depends on what the application expects to be in the
text. For example...
object result
sequence inp
inp = getField(fldCosting) --> "$123.45 per Item"
result = conv_atom(inp) --> {123.45,8}
if sequence(result) then
cost = result[1]
description = inp[result[2]..$]
else
cost = result
description = ""
end if
And in another usage it might be more like ...
result = {}
while sequence(result) do
inp = ask_user("Enter your age") --> "I'm 19 years old"
result = conv_integer(inp) --> {0,1}
if sequence(result) then
msg("You must enter your age as a simple number (of years)")
else
user_age = result
end if
end while
or using the 'to_xxx' routine:
result = 0
while result < 1 or result > 99 do
inp = ask_user("Enter your age") --> "I'm 19 years old"
result = to_number(inp) --> 0
if result < 1 or result > 99 then
msg("You must enter your age as a simple number between 1 and 99")
else
user_age = result
end if
end while
But note that to_digits() would have returned 19 because it discards all
non-digits.
--
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell
|
Not Categorized, Please Help
|
|