[V2:] & and => should not be an operator but a keyword instead

Share your ideas as to how the documentation can be improved.
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

[V2:] & and => should not be an operator but a keyword instead

08 Sep 2023, 01:23

& and => should not be an operator but a keyword instead
From the document, the precedence of current operators is &>*>:=>=>.
However, ,&a:=5 will run a:=5 first and then Reference &.
Also, f()=>this.xx:=7 will run := first, but f2:=ths=>5 will run => first instead.
All of them above are against the precedence rules. Therefore, considering the complexity, & and => should be treated as keywords rather than operators.
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: [V2:] & and => should not be an operator but a keyword instead

08 Sep 2023, 05:39

Wouldn't those things you have in mind be explained by the details in the ":=" documentation?
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [V2:] & and => should not be an operator but a keyword instead

08 Sep 2023, 06:13

safetycar wrote:
08 Sep 2023, 05:39
Wouldn't those things you have in mind be explained by the details in the ":=" documentation?
But the document didn't say about the &. At least haven't been found currently.
Both situations are against the operator precedence. And the particular case of & hasn't been documented yet.
Once the particular case of & is documented, I guess it will be removed from the operator list and become normal keywords.
lexikos
Posts: 9593
Joined: 30 Sep 2013, 04:07
Contact:

Re: [V2:] & and => should not be an operator but a keyword instead

28 Sep 2023, 23:39

The suggestion to call & or => a keyword doesn't make sense on any level. A keyword is just a word with special meaning. & and => are combinations of symbols; they are not words. and, or and not are both keywords and operators, and are affected by operator precedence. if, local and as are keywords but not operators. & is an operator, and is affected by operator precedence like any other prefix operator.

Whether it is or isn't an "operator" and is or isn't a "keyword" does not imply anything about precedence.

:= overrides precedence. This is explained in the documentation. There is nothing at all special about the combination of & with :=, so no reason to mention & in particular.

=> could be said to override precedence in the same way as :=; i.e. it has higher precedence than anything to its left. This isn't explained anywhere, but interpreting a ?? b => c as (a ?? b) => c obviously wouldn't make any sense, just as it wouldn't make sense to interpret a + b(c) as (a + b)(c). It could be placed under "The following types of sub-expressions override precedence/order of evaluation" instead.

The documentation tells you that the parentheses around the parameter list of => can only be omitted when "the parameter list consists of only a single parameter name", which implies that any operator to the left of the parameter name is not part of the parameter list and therefore not part of the => function. That's also common sense, anyway.
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: [V2:] & and => should not be an operator but a keyword instead

27 Oct 2023, 00:43

lexikos wrote:
28 Sep 2023, 23:39
=> could be said to override precedence in the same way as :=; i.e. it has higher precedence than anything to its left.
Thanks for the answer. It explains well how right-associative operators work, currently.

Return to “Suggestions on Documentation Improvements”

Who is online

Users browsing this forum: No registered users and 17 guests