1. Why not == ?
- Posted by achury Nov 05, 2022
- 776 views
Sometimes I get tired of using equal() to compare sequences.
Why not == or === as phyton does?
2. Re: Why not == ?
- Posted by Icy_Viking Nov 05, 2022
- 754 views
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.
3. Re: Why not == ?
- Posted by achury Nov 05, 2022
- 732 views
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
4. Re: Why not == ?
- Posted by irv Nov 05, 2022
- 734 views
? {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
5. Re: Why not == ?
- Posted by achury Nov 05, 2022
- 700 views
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
6. Re: Why not == ?
- Posted by Bhupen1277 Nov 06, 2022
- 654 views
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()
7. Re: Why not == ?
- Posted by Spock Nov 06, 2022
- 652 views
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
8. Re: Why not == ?
- Posted by SDPringle Nov 07, 2022
- 600 views
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.
9. Re: Why not == ?
- Posted by ghaberek (admin) Nov 07, 2022
- 603 views
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:
- Only use = for boolean operations on sequences inside if and while statements.
- Issue a warning for statements like foo = a = b that equal() should be used instead.
- Possibly remove support for foo = a = b statements sometime later?
-Greg
10. Re: Why not == ?
- Posted by SDPringle Nov 07, 2022
- 581 views
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.
11. Re: Why not == ?
- Posted by ghaberek (admin) Nov 07, 2022
- 568 views
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
12. Re: Why not == ?
- Posted by SDPringle Nov 07, 2022
- 577 views
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