[swift-evolution] [Review] SE-0077 v2: Improved operator declarations

Joe Groff jgroff at apple.com
Thu Jun 30 11:08:57 CDT 2016

> On Jun 30, 2016, at 2:34 AM, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> https://github.com/apple/swift-evolution/blob/master/proposals
> /0077-operator-precedence.md
> Idea #1
> There is a high chance that 'higherThan'/'lowerThan' names will be 
> chosen. I still see a problem with that. Keywords in Swift are written 
> in full lowercase, so we should actually take 'higherthan'/'lowerthan'.
> But then what's the point of the preposition? It blends with 
> higher/lower and doesn't actually add any clarity. So we should drop 
> 'than' and have just higher/lower or above/below or succeeds/preceeds or 
> whatever we choose, but *in a single word*.

These aren't formal keywords, though, they're contextual to a precedence group declaration.

> Idea #2
> I personally don't like the direction in which the proposal moved (I 
> understand the reasons). Before the first review, consensus seemed to be 
> on this:
> precedence Multiplicative {
>    above Additive
>    below Exponentiative
> }
> And now:
> precedencegroup MultiplicativePrecedence {
>    higherThan: AdditivePrecedence
>    lowerThan: ExponentiativePrecedence
> }
> Don't you have a feeling that something cute and 'swift' was turned into 
> a monster?
> At least, if we change keywords, we will get this:
> precedence MultiplicativePrecedence {
>    above: AdditivePrecedence
>    below: ExponentiativePrecedence
> }
> I also like in above/below that they are written with the same number of 
> letters, meaning that they will line up nicely.

To reiterate the core team's rationale, precedence groups ought to be a relatively rare thing. Few users ought to be defining new operators, fewer still new precedence groups. Furthermore, the '-Precedence' word clarifies the use site in an operator decl:

	infix operator ΒΆ : PilcrowPrecedence

making it clear that the ':' is associating a precedence with the operator. Since operator decls are themselves hopefully rare as well, this added clarity should hopefully save unfamiliar users a trip to Stack Overflow.


More information about the swift-evolution mailing list