1. Why not == ?

Sometimes I get tired of using equal() to compare sequences.

Why not == or === as phyton does?

new topic     » topic index » view message » categorize

2. Re: Why not == ?

achury said...

Sometimes I get tired of using equal() to compare sequences.

Why not == or === as phyton does?

Wouldn't using "=" without the quotes work basically the same as equal()? Its been awhile since I've used equal(). Although have == as in C would be nice too. I'm against have three equal signs, that's gross like javascript.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Why not == ?

Try this:

? equal(2, 2) 
? equal({2,3,4}, {2,3,4}) 
? 2=2 
? {2,3,4}={2,3,4} 

equal() and "=" are the same for atoms, but not for sequences.

Marco Achury

new topic     » goto parent     » topic index » view message » categorize

4. Re: Why not == ?

? {2,3,4}={2,3,4}  --> {1,1,1} 
? {2,3,4}={2,5,4}  --> {1,0,1} 
? equal({2,3,4},{2,3,4}) --> 1 
? equal({2,3,4},{2,5,4}) --> 0 
? {2,3,4}={2,5,4,1} --> sequence lengths are not the same (3 != 4)  
? equal({2,3,4},{2,5,4,1}) --> 0 
? compare({2,3,4},{2,3,4}) --> 0 
? compare({2,3,4},{2,3,5}) --> -1 
? compare({2,3,5},{2,3,4}) --> 1 
? compare({2,3,4},{2,3,4,5} --> -1 
new topic     » goto parent     » topic index » view message » categorize

5. Re: Why not == ?

What I mean in the original post. Is that compare 2 sequences is a very frequent action, and equal() is not very ergonomic. So would be nice to have a shorthand for it.

Manual says that "? x" is a shorthand for "pretty_print(1, x)"

Would be nice if

"a==b" or "a===b" become a shorthand for "equal(a, b)"

The triple equal is nice because is not easy to write it as mistyping. On javascript means that compare value and type, so is equivalent to the function of equal()

Marco Achury

new topic     » goto parent     » topic index » view message » categorize

6. Re: Why not == ?

achury said...

Sometimes I get tired of using equal() to compare sequences.

Why not == or === as phyton does?

Euphoria's roots are from APL. Today we have the "←" and " →" symbols available easily.
It would be prudent to use these for assignment and storage and use "=" for equal()

new topic     » goto parent     » topic index » view message » categorize

7. Re: Why not == ?

Bhupen1277 said...
achury said...

Sometimes I get tired of using equal() to compare sequences.

Why not == or === as phyton does?

Euphoria's roots are from APL. Today we have the "←" and " →" symbols available easily.
It would be prudent to use these for assignment and storage and use "=" for equal()

In the programming system I use [Orac - basically a super pre-processor for Euphoria incorporating an intelligent editor, incremental compilation etc] all comparisons - regardless of type - can use the standard operators but the final output is compiled to the verbose functions, eg:

if a = b then -- this becomes 
if equal(a,b) then 
 
if a < b then -- this becomes [I believe] 
if compare(a,b) = -1 then 
 
etc 

When the compiler can detect an atomic comparison the native operator is left intact.

I can't imagine ever using clunky verbose functions for normal comparisons. And I never had a problem with assignments using the same operator, eg:

a = b=c -- a must be either 1 or 0 

Spock

new topic     » goto parent     » topic index » view message » categorize

8. Re: Why not == ?

Yes = is a much better syntax for what today's Euphoria is equal(). The only downside is breaking old code which is probably is minor thing to fix.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Why not == ?

A long time ago I had made a custom Euphoria interpreter that converted a = b to equal(a, b) when the operator was used inside an if or while statement. IIRC it may have had some bugs and I'm pretty sure I've since lost the code.

This is something I'd like to see implemented and I don't think it would break much existing code since boolean statements have to be atoms and all binary operations on sequences return a sequence or cause an error (if sequence lengths do not match).

I think the potential problems come from the reverse: statements like foo = a = b where a and b are equal-length sequences so foo would return a sequence as well. I think the solution here is two-fold:

  1. Only use = for boolean operations on sequences inside if and while statements.
  2. Issue a warning for statements like foo = a = b that equal() should be used instead.
  3. Possibly remove support for foo = a = b statements sometime later?

-Greg

new topic     » goto parent     » topic index » view message » categorize

10. Re: Why not == ?

I like the idea of using Python like relationals:

a == b == c is true iff a == b and b == c 
a < b < c is true iff a < b and b < c 

This is another breaking change.

new topic     » goto parent     » topic index » view message » categorize

11. Re: Why not == ?

SDPringle said...

I like the idea of using Python like relationals:

a == b == c is true iff a == b and b == c 
a < b < c is true iff a < b and b < c 

This is another breaking change.

Right now we'd be using if a = b and b = c or if a < b and b < c which IMHO is perfectly fine, but it certainly gets verbose and eliminating the extra b could help reduce errors.

A backwards-compatible option here would be to allow equal() and compare() to accept more than two parameters, or simply a third parameter, that defaults to NOVALUE.

So a == b == c becomes equal(a, b, c) and returns 1 if all parameters are equal and a < b < c becomes compare(a, b, c) and returns -1 if each parameter is less than the next, etc.

-Greg

new topic     » goto parent     » topic index » view message » categorize

12. Re: Why not == ?

Yes. Perhaps it is too annoying to make these changes. It is a bit like changing to metric when pretty much everything is measured in SAE already and all except the youngest already know SAE.

integer a = 2,b = 3,c = 3 
a = b = c 
-- Euphoria.  a is now 1 
a = 2 
b = 3 
c = 3 
a = b = c 
# Python.  a is now 3 
new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu