-
Notifications
You must be signed in to change notification settings - Fork 86
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
Add discard feature #596
Add discard feature #596
Conversation
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 looks fine, my two comments are just optional suggestions on presentation not content.
standard/expressions.md
Outdated
@@ -5678,7 +5678,7 @@ assignment_operator | |||
|
|||
The left operand of an assignment shall be an expression classified as a variable, a property access, an indexer access, or an event access. | |||
|
|||
The `=` operator is called the ***simple assignment operator***. It assigns the value of the right operand to the variable, property, or indexer element given by the left operand. The left operand of the simple assignment operator shall not be an event access (except as described in [§14.8.2](classes.md#1482-field-like-events)). The simple assignment operator is described in [§11.18.2](expressions.md#11182-simple-assignment). | |||
The `=` operator is called the ***simple assignment operator***. When the left operand is not a discard (§discards-new-clause), this operator assigns the value of the right operand to the variable, property, or indexer element given by the left operand. Otherwise, the right operand is evaluated with its value being discarded. The left operand of the simple assignment operator shall not be an event access (except as described in [§14.8.2](classes.md#1482-field-like-events)). The simple assignment operator is described in [§11.18.2](expressions.md#11182-simple-assignment). |
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.
Should we make it more obvious that the right operand is always evaluated by stating that first? Something along the lines of:
The
=
operator is called the simple assignment operator. This evaluates the right operand and then either: assigns the value to the variable, property, or indexer element given by the left operand; or discards the value if the left operand is a discard (§discards-new-clause). The left operand of the simple assignment operator shall not be an event access (except as described in §14.8.2). The simple assignment operator is described in §11.18.2.
standard/variables.md
Outdated
|
||
Under certain circumstances, a discard may be used in the same scope as an explicitly declared variable named `_`. | ||
|
||
For details of using discards when deconstructing tuples, see §deconstruction-expressions-new-clause. When calling methods with `out` parameters, see [§14.6.2.4](classes.md#14624-output-parameters). In a pattern-matching operation with the `is` and `switch` statements, see [§11.11.11](expressions.md#111111-the-is-operator) and [§12.8.3](statements.md#1283-the-switch-statement), respectively. As the left operand of a simple assignment, see [§11.18.2](expressions.md#11182-simple-assignment). |
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.
Maybe a list, textual or bullets? This is just changing punctuation but might be clearer, e.g.
For details of using discards: when deconstructing tuples, see §deconstruction-expressions-new-clause; when calling methods with
out
parameters, see §14.6.2.4; in a pattern-matching operation with theis
andswitch
statements, see §11.11.11 and §12.8.3, respectively; and as the left operand of a simple assignment, see §11.18.2.
or
For details of using discards:
ed10ff9
to
c3b3d9f
Compare
standard/variables.md
Outdated
|
||
Under certain circumstances, a discard may be used in the same scope as an explicitly declared variable named `_`. | ||
|
||
For details of using discards when deconstructing tuples, see §deconstruction-expressions-new-clause. When calling methods with `out` parameters, see [§14.6.2.4](classes.md#14624-output-parameters). In a pattern-matching operation with the `is` and `switch` statements, see [§11.11.11](expressions.md#111111-the-is-operator) and [§12.8.3](statements.md#1283-the-switch-statement), respectively. As the left operand of a simple assignment, see [§11.18.2](expressions.md#11182-simple-assignment). |
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 is causing the build issue. The deconstruction-expression-new-clause
isn't resolving.
Where to describe discards in the spec? I don’t think it warrants being in the “Basic concepts” chapter. The “Variables” chapter looks like the best fit. My initial thought was to make discards a new variable category. However, as a discard is a pseudo-variable, my current thinking is to describe it in a new top-level section in the variables chapter. Basically, we don’t want to have to change any existing prose w.r.t variables to exclude discards. Better to make them sort-of-but-not-quite-variables! And while a variable name is a *variable_reference*, a discard is not.
c3b3d9f
to
0d38139
Compare
Closed in favor of #664 |
This PR addresses the discard part of Issue #561 as well as the use of a discard on the lhs of simple assignment, which was previously covered by PR #44. That text will be removed from PR 44, and that PR will be revised to reflect PR 596's existence.
I have yet to review PR #61 or #63 in terms of this new PR. When I eventually do so, I might need to come back and tweak this PR.
The local-variable creation part of Issue #561 will be addressed separately.