Infix for isequal

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.


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 >=.


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)
a <~ b ≝ islessorequal(a,b) and a >~ b ≝ isgreaterorequal(a,b)

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

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

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.

1 Like

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 :wink:, 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.