Replies: 1 comment 1 reply
-
Another solution may be to disallow all the described cases that are likely to create confusion and force the user to specify the brackets |
Beta Was this translation helpful? Give feedback.
1 reply
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
-
Similarly to #1007, there doesn't seem to be any discussion in the Reference of the precedence of the "empty operator" meaning function application. As far as I'm concerned, it seems not to bind tightly enough. For example, suppose you see:
a b < c
Which is a better interpretation:
a(b) < c
ora(b<c)
? I would contend the former is much more common and likely what is intended; I think there are more functions returning things that can be compared than there are functions that take a boolean, in practice. Currently it's interpreted asa(b<c)
, though.With some experimentation, it appears that juxtaposition is the lowest possible precedence. I suppose one might argue that this is forced by the fact that
a b, c
definitely parses asa(b,c)
nota(b),c
, and comma is the lowest possible precedence operator, so therefore juxtaposition has to be the lowest possible. But I would argue that the comma ina b, c
is not the comma operator, but rather a tupling operator, which can and does have different precedence.Where would I personally put juxtaposition? Looking at the table, the highest line I feel like it should definitely be tighter binding than is relational operators; and the lowest line I feel like it should obviously be looser binding than is exponentiation (
a b**2
should bea(b**2)
. But I think it would be weird for it to break up the set of arithmetic operations (why woulda b * c
bea(b*c)
buta b + c
bea(b) + c
? So I think it should either go just above or just below the shift operators (I don't use those enough to have any feelings about their precedence). Insofar as shifts are "like" arithmetic, juxtaposition should be looser-binding than shifts.This whole discussion is about precedence vs operators to the right of juxtaposition, which is unusual in that its precedence differs in the two directions. Versus operators to the left of the juxtaposition, it already has very high precedence; it binds more tightly than new, which is near the top of the hierarchy.
Note that all my suggestions would mean that
a b < c, d
would parse asa(b) < c, d
whereasa b + c, d
would parse asa(b+c, d)
, which I am fine with. If you wanta(b<c, d)
, you can just write that. There are a lot more common situations where parentheses definitely have to be forced, such as a function call as a non-final argument to another function call.Beta Was this translation helpful? Give feedback.
All reactions