[swift-evolution] [Proposal] Custom operators

Chris Lattner clattner at apple.com
Sat Apr 9 08:36:56 CDT 2016


> On Apr 8, 2016, at 10:46 AM, Антон Жилин via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Right, `infix` operators without a precedence group logically should be able to be used, just with parentheses everywhere.
> 
> But users will most likely want to use such operators with `=` without parentheses. It means, such operators should still belong to some precedence groups.
> 
> I suggest that for each such operator, an separate unnamed group should be created. It will have no associativity and precedence greater than Ternary (I actually agree this is the right choice).
> 
> I also think it is OK that other operators will not be able to specify precedence relation with such "unprecedented" operators

Right, I agree.  I consider it to be the "safe default" for an operator to be non-associative and unordered with respect to all other operators.  This would require using parentheses to disambiguate, which seems safer than a default precedence level.  This proposal also eliminates the notion of a strictly ordered set of precedences.

I do think it is useful to be able to specify precedence relationships without having to define a “group”, to avoid boilerplate when you have one operator at a logical level (“??” for example).

-Chris


More information about the swift-evolution mailing list