Re: type string
Here's my recursive solution:
global type string(sequence s)
integer i
i = length(s)
if (i=0) or (integer(s[i]) and (s[i]>0) and (s[i]<=255) and
string(s[1..i-1])) then
return 1
end if
return 0
end type
I haven't benchmarked it, and don't know how penalized are recursive calls.
Anyways Euphoria short-circuit evaluation should stop the recurse as soon
as an invalid entry is detected.
I tried with a direct return statement, but short-circuit evaluation only
works for if and while statements. I understand that short-circuit may
render unwanted results for general purpose boolean operations, but in the
context of a type declaration, where only true/false values can be returned
(same case as if and while) there could be a way to override the default
behaviour. Maybe "with/without short_circuit" keywords could be implemented
Rob. Or even create short-circuit specific boolean operators: sc_or,
sc_and, sc_xor.
Regards,
Daniel Berstein
[daber at pair.com]
|
Not Categorized, Please Help
|
|