You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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:
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.The text was updated successfully, but these errors were encountered: