evincarofautumn / kitten

A statically typed concatenative systems programming language.
http://kittenlang.org/
Other
1.1k stars 39 forks source link

Named precedence levels #180

Open evincarofautumn opened 7 years ago

evincarofautumn commented 7 years ago

There aren’t many operators defined in the common vocabulary yet, so we still have the chance to figure out the ergonomics of custom operators. Instead of the current 0–9 precedence levels, it might be better to use named precedence levels, under the assumption that most operators could (and should) fall into a clear family, such as:

Number Name Examples
9 ?
8 tight exponential ^*
7 tight multiplicative * / %
6 tight additive + -
5 ? ~**
4 relational < > <= >= = <>
3 loose multiplicative & &&
2 loose additive | ||
1 ? --> --->
0 ?

* not yet in the common vocab ** strict difference (xor)

Pros and cons:

suhr commented 7 years ago

Why don't just use an operator as a precedence level? Something like infixl ÷ (/).

evincarofautumn commented 7 years ago

That could work, and it’s been done in a few languages, at least Perl6 and Fortress. I just figured it would come out more organised to use names for the groups, provided we can come up with sensible names.

suhr commented 7 years ago

I just figured it would come out more organised to use names for the groups, provided we can come up with sensible names.

To be honest, the concept of precedence levels by itself feels like a kludge. Even though it is a most simple and direct way to implement precedences.

sullyj3 commented 7 years ago

Interesting alternative approach: https://youtu.be/EZD3Scuv02g?t=31m42s

Heimdell commented 6 years ago

Its may be worth to do operator precedence like in Agda: you can only declare fixity and the fact that the operator in question binds tighter that some other (and the relation is not transitive).

Using operators with no order known without putting one of subexpr in () is a suntax error.

Then you have to construct a lattice, of course.