1. Re: Short Circuiting/goodies.e
[Short Circuiting]
My own two cents here. I found it suprising that Euphoria doesn't allow
short circuiting,
since it requires that ranges be checked, or it will blow up.
For example, I was coding something like this the other day:
if compare( s[1..3], "EOF" ) then
...
else
...
end if
(See Robert? I'm always forgetting that '=0'...)
Anyway, you need to make sure that length(s) > 3. So the newbie test
becomes:
if length( s ) >= 3 and compare( s[1..3], "EOF" ) = 0 then
...
else
...
end if
Boom! As soon as a length < 3 comes along, the code crashes. So it's
modified to:
if length( s ) > 2 then
if compare( s[1..3], "EOF" ) = 0 then
...
end if
else
...
end if
Only now, I'm stuck not being able to get to the 'else' portion of the
logic. Grrr...
Now, I know that I can write a "safe" slice comparison routine, like:
function slice( sequence s, integer i1, integer i2 )
-- "safer" slice. returns slice of requested size
-- still blows up with slice sizes of < 1, etc.
integer l
l = length( s )
if l < i2 then
s = s & repeat( 0, i2-l )
end if
return s[i1..i2]
end function
and then the code becomes reasonable again:
if compare( slice( s, 1, 3 ), "EOF" ) = 0 then
...
else
...
end if
Anyway, back to the point: we get stuck BOTH ways: Euphoria blows up
when the ranges are not checked, but often makes us jump through hoops
to check the ranges.
[Goodies]
I've been complaining to Robert that I always forget the '= 0' on tests
like:
if compare( s, "EOF ) =0 then
and wanted:
if same( s, "EOF" ) then
built into Euphoria. He kindly suggested that this was material more
appropriate for an include file.
I offer the slice() function for that same hypothetical include file
("goodies.e"), along with:
global constant
TRUE = 1,
FALSE = 0
I'd include the new DOS functions that were posted the other day, but
I'm thinking that the routines should be usable by both Win32 and DOS32.
Any more suggestions of things to include?
-- David Cuny