Some examples where explicitly ignoring a value is needed. foreach (_; 0 .. 10) {} foo((a, _) => a); A more advanced implementation might also allow to use _ in assignments not only as declarator. TypeTuple!(a, b, _) = tup[]; The compiler should disallow to access declarations named _, after deprecation. The identifier _ should not be checked for variable shadowing to allow nested declarations of _. If possible the compiler should not generate code to assign/initialize such declarations, unless the operation has a side-effect.
I've added my vote. Once "_" means "ignored" (and it has become a name that can't be read), you can allow code like this where "_" is used more than once: foreach (_; 0 .. 5) foreach (_; 0 .. 5) {} foo((a, _, _) => a); // some kind of tuple destructuring syntax: @{a, b, _} = myTup; Other potentially important usages of the "ignored" value are for pattern matching "ignored" wild-card.
one of my so-much-universally-hated ;-) patches does exactly this (but for '__' args — two underscores) for foreach args and lambda args (maybe function args too, i don't remember). it's such an amusement to see people requesting same things again and again. as for 'foreach', this should be allowed too: `foreach (; 0..42)`. i'm using this for some time now and found it very handy.
Would this cause interop problems with C programs that use GNU gettext, which conventionally defines '_' to be shorthand for 'gettext'? (Not that I care about such an ugly C hack, but you never know, somebody might care.)
it shouldn't, but we can use two underscores for that. ids started with two underscores are reserved anyway.
There are plans to totally disallow the use of "_" as variable name in Java: http://openjdk.java.net/jeps/213 >In addition, using underscore ("_") as an identifier, which generates a warning as of Java SE 8, should be turned into an error in Java SE 9.<
There is precedence for this usage in python, haskell and scala.