Re: if statement not working
I'm sorry. I've had a decent sleep now. Yesterday was not a good day at the
office.
----- Original Message -----
From: "Graeme" <graemeburke at hotmail.com>
To: "EUforum" <EUforum at topica.com>
Subject: Re: if statement not working
>
> At 07:04 AM 3/22/02 -0800, you wrote:
> >
> >Graeme wrote:
> >
> >> But seriously, having the interpreter return a valid result
> >> from accessing non-existant data is just way stupid.
> >
> >Is there really a need to make the attack so personal?
>
>
> Well that's EXACTLY what i thought.....
>
> Sorry David. There was nothing of a personal nature in my
> post, unless you mean the word 'stupid'. I used it because
> its the same word Derek used to describe his opinion in the
> post I was replying to. I quoted his comment in my post. You
> have removed this from the top of your reply, as I'm sure you
> must be aware.
>
And Graeme, you are absolutely correct. I was angry over some poor decisions
that colleagues of mine had made; committing my time to projects interstate
for months on end, without consulting me, or my bosses. I've calmed down a
lot now.
>
> >So if i were to ask you to return all 100K bytes of this
> >email, you'd land in a mental institution? Eu would,
> >figuratively speaking.
>
> >Kat
>
>
> So if you asked me for $100 and I diddnt have it so i gave
> you 3 $10 notes and the rest in monopoly money that would
> be ok?
>
> AND HERES THE REAL PROBLEM --->
>
> What if you dont notice, then you go to the supermarket and
> and try to pay for your groceries? Will the cashier accept
> the monopoly money? Maybe. Hopefull not, because every time
> somebody accepts it, the bug is one step further down the line,
> and when it enevtaully stops, you've got a hell of a mess trying
> to figure out who's handing out the bad cash...
>
It is good that Euphoria doesn't allow you access to non-existant sequence
elements. Thus :
s = "abc"
t = s[1..4]
Eu is proper to reject this.
My problem still remains though, and I don't have a reasonable solution yet.
Simply put, I don't care how many elements the sequences have, all I want to
know is : does one object begin with another object? I suppose the simplest
approach is:
s = upper(trim(t))
if match("*AUTHOR ", s) = 1 then
GameInfo[vAuthor] = t[9.. length(t)]
...
elsif match("*COPYRIGHT ", s) = 1 then
GameInfo[vCopyright] = t[12.. length(t)]
...
elsif match("*TITLE ", s = 1) then
GameInfo[vTitle] = t[8.. length(t)]
...
However, in my never-ending quest for readable code, the phrase "match(a,b)
= 1" is not obviously telling the reader that I'm trying to see if 'a'
begins with 'b'. That's part of the ambiguitity of using literal numbers in
code; you don't know if they are special (magic) numbers or not. So I could
make it a bit better by doing:
constant beginning = 1
. . .
if match("*AUTHOR ", s) = beginning then
but that looks a bit ambiguous too. Or :
if begins(s, "*AUTHOR ") then
but that sounds unusual if you say it out loud.
What I'd really, really like to write is something like:
structure GameInfo
sequence Title
sequence Author
sequence Copyright
end structure
GameInfo theGame
. . .
case upper(trim(t)) do
when begins "*AUTHOR " then
theGame.Author = t[9..$]
...
when begins "*COPYRIGHT " then
theGame.Copyright = t[12..$]
...
when begins "*TITLE " then
theGame.Title = t[8..$]
...
end case
but I know that ain't going to happen
-----------
cheers,
Derek
|
Not Categorized, Please Help
|
|