-
Notifications
You must be signed in to change notification settings - Fork 334
Consistent operator section semantics (and enable unused operator section warning) #14117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1a47914
2fee764
6ef8fd6
326f9f4
4bbeb8c
0060f72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -417,15 +417,26 @@ result = 1..100 . each random . take 10 . sort | |
| ### Sections | ||
|
|
||
| An operator section is a nice shorthand for partially applying an operator. It | ||
| works as follows. | ||
|
|
||
| - Where an argument is not applied to an operator, the missing argument is | ||
| replaced by an implicit `_`. | ||
| - The application is then translated based upon the rules for | ||
| [underscore parameters](./function-parameters.md#underscore-parameters) | ||
| described later. | ||
| - The whitespace-based precedence rules discussed above also apply to operator | ||
| sections. | ||
| works as follows: | ||
|
|
||
| - When a binary operator is referred to without providing parameters, its value | ||
| is a function with two parameters (left followed by right). This can be | ||
| written either by wrapping the operator in parentheses, or by using it in an | ||
| unspaced expression without any operand: | ||
| ```enso | ||
| [1, 2, 3].reduce (+) . should_equal 6 | ||
| [1, 2, 3].reduce function=+ . should_equal 6 | ||
| ``` | ||
| - When a binary operator is applied to a single parameter, the result is a | ||
| function accepting the parameter. | ||
| ```enso | ||
| [1, 2, 3].map (1 /) . should_equal [1.0, 0.5, 0.3333333333333333] | ||
| [1, 2, 3].map (/ 1) . should_equal [1.0, 2.0, 3.0] | ||
| [1, 2, 3].map function=1/ . should_equal [1.0, 0.5, 0.3333333333333333] | ||
| [1, 2, 3].map function=/1 . should_equal [1.0, 2.0, 3.0] | ||
| [1, 2, 3].map 1/ . should_equal [1.0, 0.5, 0.3333333333333333] | ||
| [1, 2, 3].map /1 . should_equal [1.0, 2.0, 3.0] | ||
| ``` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for modifying the documentation! |
||
|
|
||
| ## Mixfix Functions | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1153,7 +1153,6 @@ yield switch (translateExpression(group.getBody(), false)) { | |
| .build(); | ||
| } | ||
| case Tree.Function fun -> translateFunction(fun); | ||
| case Tree.OprSectionBoundary bound -> translateExpression(bound.getAst(), false); | ||
| case Tree.UnaryOprApp un when "-".equals(un.getOpr().codeRepr()) -> | ||
| switch (translateExpression(un.getRhs(), false)) { | ||
| case Literal.Number n -> | ||
|
|
@@ -1180,8 +1179,6 @@ yield switch (translateExpression(group.getBody(), false)) { | |
| .location(getIdentifiedLocation(un)) | ||
| .build(); | ||
| } | ||
| case null -> | ||
| translateSyntaxError(tree, new Syntax.UnsupportedSyntax("Strange unary -")); | ||
| }; | ||
| case Tree.TemplateFunction templ -> translateExpression(templ.getAst(), false); | ||
| case Tree.Wildcard wild -> new Name.Blank(getIdentifiedLocation(wild), meta()); | ||
|
|
@@ -1400,7 +1397,6 @@ Tree applySkip(Tree tree) { | |
| yield tree; | ||
| } | ||
| case Tree.UnaryOprApp app -> app.getRhs(); | ||
| case Tree.OprSectionBoundary section -> section.getAst(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, looks like a simplification. |
||
| case Tree.TemplateFunction function -> function.getAst(); | ||
| case Tree.AnnotatedBuiltin annotated -> annotated.getExpression(); | ||
| case Tree.ExpressionStatement statement -> statement.getExpression(); | ||
|
|
||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,9 +161,6 @@ add_specs suite_builder = | |
| r4.pretty . should_equal "Table.new [['foo', [1, 2, 3]], ['bar', [False, True, False]], ['date', [Date.new 2022 8 27, Date.new 1999 1 1, Date.new 2012 1 23]], ['time', [Time_Of_Day.new 18, Time_Of_Day.new 1 2 34, Time_Of_Day.new 12]]]" | ||
| Debug.eval r4.pretty . should_equal r4 | ||
|
|
||
| group_builder.specify "allows setting the column type" <| | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great if the new syntax can discover errors like this! |
||
|
|
||
|
|
||
| group_builder.specify "should handle error scenarios gracefully" <| | ||
| Table.new [["X", [1,2,3]], ["Y", [4]]] . should_fail_with Illegal_Argument | ||
| Table.new [["X", [1]], ["X", [2]]] . should_fail_with Illegal_Argument | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is now about TemplateFunction, right?