1. Re: [If/then and sequences...]

On Wed, 30 Aug 2000, you wrote:
> --
>    "C" uses == ( double equal signs ) for comparison
>        and  =  ( single equal sign  ) for assignment
>
>     which makes good sense and I think would be easy to implement.
>
>     Bernie

True enough. But the real problem is not telling the difference between
assignments and equality, Euphoria doesn't mix those up, and neither do
I.  The problem is Euphoria's inability to handle the "if"  statement.
correctly when  followed by an =, < or > operator using sequences.

Example:
sequence a,b
a = {1,2,3}
b = {1,2,3,4}

if a = b then puts(1,"EQUAL")
else puts(1,"Not Equal")
end if

Doesn't run, gives error message "sequence lengths are not the same (3 != 4)  "
Well, if b is longer than a, then it's a pretty good chance (~100%) that they're
NOT equal. So why abort? Why not just go ahead and print "Not Equal"?

Now, I realize that > and < aren't so clear cut.
a = "Aaron"
b = "Abe"
Equality here is, again, no problem. They're not equal by anyone's definition.
Is Abe > Aaron?  It would be in an alpha sort.
OTOH, Abe is shorter, so maybe it's less.

Let's see what compare() says:
? compare(a,b)
-1 -- ok, what does -1 mean?  according to the manual, -1 means  a < b
Note, there is no error message about "sequence lengths not the same"
here. It just works.

Yet, if you try the following:
if a < b then puts(1,"Aaron comes first")
end if

You'll get the following message:
sequence lengths are not the same (5 != 3)

Which proves two things:
1. Euphoria _already knows_ it's working with two sequences (see the lengths?))
2. Euphoria doesn't bother to try a compare on the two known sequences, just
aborts with an error. If it called compare, then it would return TRUE
( a is < b according to its own rules)

Making this "if" work correctly just couldn't be all that hard - after all,
half the work is already done - detecting that two sequences were passed.
I see no reason why fixing this problem would affect in any way the other
legitimate uses of = < > ...e.g:

a = "Tim"
b = "Tom"
? (a = b)

{1,0,1}

--
Regards,
Irv

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu