# Infix for isequal

**URL:** <https://discourse.julialang.org/t/infix-for-isequal/240>\
**Category:** Internals & Design\
**Created:** [November 10, 2016, 4:33pm UTC](https://discourse.julialang.org/t/infix-for-isequal/240 "2016-11-10T16:33:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 10, 2016, 4:33pm UTC](https://discourse.julialang.org/t/infix-for-isequal/240/1 "2016-11-10T16:33:36Z")

</div>

I find I use `isequal` a lot, especially for tests, so an infix form would be convenient. I checked the issues, but did not find anything related, thought I would ask here before opening an issue.

I don’t have a strong preference for a particular symbol, but if we restrict to less esoteric LaTeX symbols, ≅ (`\cong`) is free and already recognized by the REPL.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 10, 2016, 4:46pm UTC](https://discourse.julialang.org/t/infix-for-isequal/240/2 "2016-11-10T16:46:23Z")

</div>

I’ve thought about this a lot. Since it’s such a core operation, it would be nice to have an ASCII syntax for it. E.g. `~` or `~=` or something. One thing to consider is that you’ll want to have corresponding operators for `isless` and once you go operator with that you’ll want all the analogues of `==`, `!=`, `<`, `>`, `<=` and `>=`.

Related:

> <https://github.com/JuliaLang/julia/issues/19148>
>
> There have been endless discussions about equality and inequality (e.g. https://…github.com/JuliaLang/julia/issues/18485), many of the pains of which come from the fact that IEEE 754 mandates numerical comparisons which arguably beneficial for numerical analyis, have impressively bad consequences for language semantics for things like hashing and sorting. So here's the crazy idea that came up recently...
> 
> Normal comparisons \`==\`, \`!=\`, \`\<\`, \`\>\`, \`\<=\` and \`\>=\` do sane (i.e. non-IEEE) comparisons:
> \- these are used by hashing and sorting for all things
> \- \`==\` is reflexive and transitive, including \`NaN == NaN\`
> \- \`-0.0 \< 0.0\` and \`-0.0 != 0.0\`
> 
> Introduce \`~==\`, \`~!=\`, \`~\<\`, \`~\>\`, \`~\<=\` and \`~\>=\` (or something) for IEEE comparisons:
> \- only used explicitly by user code
> \- defaults to calling normal comparisons
> \- \`NaN ~!= NaN\`
> \- \`-0.0 ~== 0.0\`

---

<div class="post-metadata">

**Author:** ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Post date:** [November 13, 2016, 4:59pm UTC](https://discourse.julialang.org/t/infix-for-isequal/240/3 "2016-11-13T16:59:18Z")

</div>

Limited to two character operators and only ASCII7 keys, it is difficult to get analogues of all the comparatives.  
Here is one way.

`a ~ b ≝ isequal(a,b)` , ` a !~ b ≝ !isequal(a,b)`  
` a ~< b ≝ isless(a,b)` and `a ~> b ≝ isgreater(a,b)`  
if using braces is not a parser problem  
` a ~{ b ≝ islessorequal(a,b)` and `a ~} b ≝ isgreaterorequal(a,b)`  
else  
` a <~ b ≝ islessorequal(a,b)` and `a >~ b ≝ isgreaterorequal(a,b)`

otherwise  
`a ~ b ≝ isequal(a,b)` , ` a !~ b ≝ !isequal(a,b)`  
` a ~< b ≝ isless(a,b)` and `a ~> b ≝ isgreater(a,b)`  
`!(a ~< b) ≝ isgte(a,b)` and `!(a ~> b) ≝ islte(a,b)`  
is not too bad, though asymmetric in syntax

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [March 6, 2020, 5:39am UTC](https://discourse.julialang.org/t/infix-for-isequal/240/4 "2020-03-06T05:39:49Z")

</div>

Sorry to revive an old topic, but how about we introduce the following?

```julia
x isequal y
x isless y

```

(Instead of an ASCII or Unicode infix operator.) We already have infix `in` and `isa`, so this doesn’t seem like too much of a stretch.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 6, 2020, 6:28am UTC](https://discourse.julialang.org/t/infix-for-isequal/240/5 "2020-03-06T06:28:52Z")

</div>

I don’t think this should be done in general. It is better to have function calls to be prefix uniformly and use operators when convenient.

A key element of Julia’s design is that _very few things are “special” primitives_: eg `isequal` and `isless` could both live in packages without any problem (other than people complaining about having to `import` them to get batteries included 😉, and a bit of startup time).

Allowing functions to be used as prefix requires special-casing at the parser level, the fewer of these we have, the better. `isa` is a builtin, but having a prefix form of `in` (the function, not the part of `for` syntax) is actually an oddity.
