Description
Admin comment: this is being implemented, feature specification, implementation issue, experiment flag wildcard-variables
.
Pattern matching brought a new way to declare variables. Inside patterns, any variable whose name is _
is considered a "wildcard". It behaves like a variable syntactically, but doesn't actually create a variable with that name. That means you can use _
multiple times in a pattern without a name collision.
That leads to an irregularity:
var (_, _) = (1, 2); // OK.
var _ = 1;
var _ = 2; // Error. Already a variable in scope with this name.
Also, it's annoying that _
binds a name. When you have a lambda with more than one parameter that you don't use, you end up having to do:
takesCallback((_, __, ___) { ... });
I have a proposal to fix both by saying that local variables and parameters named _
are also non-binding. This is the tracking issue for that proposal.
Metadata
Metadata
Assignees
Type
Projects
Status