Julia: infix operators for `isequal` and `isless`

Created on 16 May 2017  Â·  13Comments  Â·  Source: JuliaLang/julia

Given the demise of https://github.com/JuliaLang/julia/issues/19148, the current state of affairs might be somewhat more palatable if isequal and isless had operator forms. One option would be making eq and lt infix operators like isa and in, but I don't love that idea. The operators I proposed in #19148 could be used: ~==, ~!=, ~<, ~>, ~<= and ~>=. Or some Unicode operators.

design speculative

Most helpful comment

As for the name, ~== is a bit too similar to MATLAB's ~= ...

All 13 comments

Making it easier to work with FP values as normal bits sounds good. As long as they don't use the operators that people normally expect to have IEEE complaint behaviors.

As for the name, ~== is a bit too similar to MATLAB's ~= ...

It seems quite likely the best place to go from here is just to allow infix for all identifiers. The main issue is probably precedence. Many of these (including the existing in and isa) would use comparison precedence, and even chained comparison (a isless b isless c), but I'm not sure how to handle it in general. Maybe a fixed list of comparisons, and give everything else the same precedence level (perhaps equal to |>?).

Of course there are some useful unicode characters like ≅ and ≨.

I don't see the benefit of using these functions infix rather than prefix. It would seem especially unfortunate to me to allow infix for all identifiers.

Infix for identifiers would mean some trouble for macros and matrices, unless infix identifiers are disallowed in space-sensitive context (which is possibly reasonable, but not the way things currently work).

(I would even go far as to suggest that infix in and isa should be removed, but I suppose the ship on that has sailed.)

Simple juxtaposition was considered a binary operator in Fortress. I wonder if something like that idea could work for Julia, especially now that every function has its own type?

Disallowing infix operators in space-sensitive context would make sense. I personally use infix in all the time and enjoy isa when I have occasion to use it.

I was the one who added infix isa, but I'll echo Jeff's concerns at the time that it's a rather slippery slope in terms of allowing infix things like this. I would argue that in and isa are very special cases and their infix use shouldn't generalize to just any operator. IMO we should generally keep words as prefix and Unicode/ASCII symbols as infix. Having Unicode operators to express non-IEEE operations seems like a reasonable compromise between convenience and consistency.

We could go the java route with equals, where equals compares nans equal and 0s unequal, while == does the opposite, but that sounds like a recipe for badness.

@oscardssmith See isequal

@oscardssmith: that was essentially my proposal in https://github.com/JuliaLang/julia/issues/19148.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

StefanKarpinski picture StefanKarpinski  Â·  3Comments

TotalVerb picture TotalVerb  Â·  3Comments

StefanKarpinski picture StefanKarpinski  Â·  3Comments

manor picture manor  Â·  3Comments

omus picture omus  Â·  3Comments