Re: Small feature request for future EU versions

new topic     » goto parent     » topic index » view thread      » older message » newer message

Patrick Barnes wrote:
> 
> On Sun, 17 Oct 2004 04:46:14 -0700, irv mullins <guest at rapideuphoria.com>
> wrote:
> > string and numeric comparisons? Several other languages do that
> > without any problem.
> > 
> > Irv
> 
> The problem is this:
> 
> constant 
> atom1=5,
> atom2=10,
> seq1={1,5,2,4},
> seq2={1,2,5,4}
> 
> constant cond1 = ( atom1 = atom2 )
> constant cond2 = ( seq1 = seq2 )
> 
> --cond1 will be 0, as 5 does not equal 10.
> --cond2 will be {1,0,0,1}, because Euphoria compares each element.

By any normal meaning of the word 'equal' as used by scientists, mathematicians,
programmers, and the corner grocer, the answer can not possibly 
be {1,0,0,1}. It is either TRUE or FALSE. If the lengths of the two 
sequences are different, then they are not equal, and the result should 
be FALSE - not an error. 

If, for some strange reason, someone wanted an item-by-item comparison 
between two sequences, then a new and more meaningful name should be chosen
for a function which returns {1,0,0,1}. 

> The problem is that the IF statement doesn't know what to do with a
> sequence, and there's not an obvious solution.
> As a quick hack, lets say that if the IF statement receives a
> sequence, it treats it as true if every element is non-zero.
> 
> That would allow us to easily compare strings using the simple form:
> if string1 = string2.
> However, what if the sequence passed to the IF statement is empty?
> What if the sequence contains multiple levels?
> What if the sequence contains a mix of non-zero integers, and an empty
> sequence?

You're thinking within the box built by RDS. 
No matter whether the sequences are empty, or contain multiple levels, 
if the two are identical, then they are equal, otherwise they aren't.
That is the obvious definition of equal which anyone can understand. 
 
> I think that these things aren't easily solved...

The whole thing could have been avoided if Rob had used the = operator 
to return equality and another operator or function to return a comparison.

....

> At least with the above suggestion, there's no broken compatibility, a
> common issue (Why can't I just use '=' to compare these strings?) is
> fixed, and it's a logical solution.

I'll bet there aren't a dozen uses of = in the existing code base. I've 
used it exactly once, and I really don't mind changing that instance to 
some new function. 

Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu