-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: Go 2: allow multiple variables with all assignment variants #30917
Comments
how about
|
I don't really understand your proposal summary.
So I'm not sure what you mean by "allow multiple variables in all assignment statements." It seems like you mean something else: in some cases it's OK to write multiple statements separated by a comma, as long as those statements are either assignment statements or increment/decrement statements. Are you suggesting that any place that a simple statement may occur, it's OK to have a comma separated list of assignment statements or increment/decrement statements? For example, can I write if a += 2, b -= 3; f(a, b) {} Why are only assignment and increment/decrement statements permitted to be used in this way? Why not any simple statement (see SimpleStmt in the language spec)? |
I called
Indeed.
I don't know a reason to comma-chain other kinds. I gave common-practice examples for the assignment/inc/decrement case. PS. Why did you open with "I don't really understand" the summary, when you clearly did? |
Because I tried to work out what you might have meant and made what appears to have been a good guess. Sometimes those guesses work, sometimes they don't. I'm looking for a principled reason to decide which kinds of statements can be comma-chained. For example, if we do this, why not permit for c <- a, c <- b; ctx.Err() == nil; c <- x, c <- y { ... } |
Is "let all assignment cases support multiple variables and/or steps" not a sufficient principle? If we could write |
I don't know what that means in terms of the language spec. The language spec doesn't have any concept of "assignment cases." It has concepts like SimpleStmt. |
Can we add a concept to the spec? e.g.
|
Alternatively to the above spec concept, here's one with only inc/dec chains, e.g.
I've added both to the proposal text. |
This does not seem to address an important enough problem in the language. It doesn't add any functionality that we don't already have. In your examples, the only one that seems clearly simpler and easier to read is changing |
Problem
Multiple variables/steps are allowed in some assignment cases, but not others.
As a result we stutter when two counters are adjusted together:
Proposal
Revise the spec to one of:
Allowing:
Thanks to @mingwho for raising this previously.
The text was updated successfully, but these errors were encountered: