proposal: Go 2: left side syntax for new variable #61933
Labels
FrozenDueToAge
LanguageChange
Suggested changes to the Go language
Proposal
v2
An incompatible library change
Milestone
Author background
Related proposals
Proposal
Within a scope, when there is a mix of existing and new variables to declare, allow some syntax to differentiate which variables need to be new within the scope.
Instead of:
a left side syntax to apply
:=
semantics on a per argument basis; here I chosenew
token as the wayThere is a particular inconsistency with
:=
behavior whether a statement is at the function root scope, or in a nested scope.With the new syntax, a mix of instantiation and existing can be specified.
or
It would also help in this common pattern:
These examples are contrived for simplicity. The examples show the mix with return value
err
, because it is so common, but the scenario applies to any left side variable. The use cases around this mixed instantiation are broad.The use of
new
as the keyword is unimportant. Any syntax that allows the variable to be marked for duck type declaration is welcome. Or, the proposal could be reversed, and "fall through" types marked, likeAdd a keyword or symbol to mark a left side parameter as "new"
Unsure, I do not have language authoring expertise.
Show example code before and after the change.
:=
assignment logicvar data mydatatype
line above a statement can become a chore whenmydatatype
is not trivial.Costs
The text was updated successfully, but these errors were encountered: