1. seq errors
I have another suggestion.... in a 141 line program, i have this:
if (length(textword) > 0) then
6 times, to avoid indexing into a zero length sequence or testing a zero
length sequence in some way. Robert, can Eu return {} or false in these
cases rather than crashing, possibly with a compiler directive to switch
between the existing crash mode and a non-crash mode?
In this way,
sequence line
if equal("?",line[0]) then
DoSomething
end if
would simply not DoSomething, rather than crashing as it does now.
thanks,
Kat
2. Re: seq errors
On Fri, 31 Dec 1999 10:30:39 -0600, Kat <KSMiTH at PELL.NET> wrote:
>I have another suggestion.... in a 141 line program, i have this:
>In this way,
>
>sequence line
>if equal("?",line[0]) then
> DoSomething
>end if
>
-- define a empty string
type empty( sequence string )
if length(string) then return 0 else return 1 end if
end type
--
sequence line
--
line = "this is the string"
if empty(line) then
-- do something
? 123
? length(line)
end if
if not empty(line) then
-- do something
? 456
? length(line)
end if
-- Kat: You can do this, which is less confusing and you will be able to
-- keep track of things easier so you don't crash.
-- Bernie
3. Re: seq errors
----- Original Message -----
From: Bernie Ryan <bwryan at PCOM.NET>
To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
Sent: Friday, December 31, 1999 2:24 PM
Subject: Re: seq errors
> On Fri, 31 Dec 1999 10:30:39 -0600, Kat <KSMiTH at PELL.NET> wrote:
>
> >I have another suggestion.... in a 141 line program, i have this:
> >In this way,
> >
> >sequence line
> >if equal("?",line[0]) then
> > DoSomething
> >end if
> >
>
>
> -- define a empty string
> type empty( sequence string )
> if length(string) then return 0 else return 1 end if
> end type
>
> --
> sequence line
>
> --
> line = "this is the string"
>
>
> if empty(line) then
> -- do something
> ? 123
> ? length(line)
> end if
>
>
> if not empty(line) then
> -- do something
> ? 456
> ? length(line)
> end if
>
>
> -- Kat: You can do this, which is less confusing and you will be able to
> -- keep track of things easier so you don't crash.
I guess i didn't make myself clear again, i am not trying to test for empty
sequences, i have vars in place of the 0, :
for loop = 1 to length(textword) do
-- morecode
-- code that may set textword to ""
if (length(textword) > 0) and not ((( textword[loop] >= 'a' ) and
textword[loop] <= 'z' )) or (( textword[loop] >= 'A' ) and
textword[loop] <= 'Z' ))) then
-- code that may set textword to ""
-- morecode
end for
If loop gets set to zero without the length test, it crashes, so i test for
zero length with every test, cause who knows what is in the file the code is
processing? If instead Eu returned "" or false, the rest of the line would
fail without crashing, and the numerous length tests wouldn't be necessary.
Kat
4. Re: seq errors
- Posted by JJProg at CYBERBURY.NET
Dec 31, 1999
-
Last edited Jan 01, 2000
EU>----- Original Message -----
EU>From: Bernie Ryan <bwryan at PCOM.NET>
EU>To: <EUPHORIA at LISTSERV.MUOHIO.EDU>
EU>Sent: Friday, December 31, 1999 2:24 PM
EU>Subject: Re: seq errors
EU>> On Fri, 31 Dec 1999 10:30:39 -0600, Kat <KSMiTH at PELL.NET> wrote:
EU>>
EU>> >I have another suggestion.... in a 141 line program, i have this:
EU>> >In this way,
EU>> >
EU>> >sequence line
EU>> >if equal("?",line[0]) then
EU>> > DoSomething
EU>> >end if
EU>> >
EU>>
EU>>
EU>> -- define a empty string
EU>> type empty( sequence string )
EU>> if length(string) then return 0 else return 1 end if
EU>> end type
EU>>
EU>> --
EU>> sequence line
EU>>
EU>> --
EU>> line = "this is the string"
EU>>
EU>>
EU>> if empty(line) then
EU>> -- do something
EU>> ? 123
EU>> ? length(line)
EU>> end if
EU>>
EU>>
EU>> if not empty(line) then
EU>> -- do something
EU>> ? 456
EU>> ? length(line)
EU>> end if
EU>>
EU>>
EU>> -- Kat: You can do this, which is less confusing and you will be able to
EU>> -- keep track of things easier so you don't crash.
EU>I guess i didn't make myself clear again, i am not trying to test for empty
EU>sequences, i have vars in place of the 0, :
EU>for loop = 1 to length(textword) do
EU>-- morecode
EU>-- code that may set textword to ""
EU> if (length(textword) > 0) and not ((( textword[loop] >= 'a' ) and
EU> textword[loop] <= 'z' )) or (( textword[loop] >= 'A' ) and
EU> textword[loop] <= 'Z' ))) then
EU>-- code that may set textword to ""
EU>-- morecode
EU>end for
EU>If loop gets set to zero without the length test, it crashes, so i test for
EU>zero length with every test, cause who knows what is in the file the code is
EU>processing? If instead Eu returned "" or false, the rest of the line would
EU>fail without crashing, and the numerous length tests wouldn't be necessary.
EU>Kat
Actually, with the short-circuting in the newer versions of Euphoria,
you can do something like the following:
sequence s
s = {}
if length(s) and s[1] = 'a' then
end if
without any errors. I tested this on Euphoria for DOS version 2.2, but
I'm pretty sure it works with some other versions also (but not the really old
versions).
Jeffrey Fielding
JJProg at cyberbury.net
http://members.tripod.com/~JJProg/