Feature #16939
closed
Alias _1 as _ for block numbered params
Added by x3qt (Jury Paliakou) over 4 years ago.
Updated over 4 years ago.
Description
I propose to alias _1
as _
for block numbered params, so the following statements should be equal –
[1,2,3].map { _1 ** 2 }
[1,2,3].map { _ ** 2 }
There is an anonymous function argument literal in Clojure and it feels natural all the way, hope we can have the one too.
I like to use _. I can see one benefit of your suggestion being that it is slightly
shorter. I am mostly neutral on the suggestion but perhaps leaning towards a bit in
favour (I have not thought it through fully yet though). [I guess it comes down to
which identifier to use in an implicit manner, be it _ or anything else.]
- Status changed from Open to Closed
It was the first candidate for a single anonymous block parameter. But we abandoned for the compatibility's sake. Too many existing programs use _
as a local variable (far too more than _1
).
We'd be happy to be proven wrong. If someone is willing to experiment and to find the solution to solve the compatibility problem, please reopen the issue.
Matz.
All the examples I could find where {|_| ...}
, which could be made compatible. I still wonder what valid code example could be incompatible. Was there such an example in the wild?
matz (Yukihiro Matsumoto) wrote in #note-2:
It was the first candidate for a single anonymous block parameter. But we abandoned for the compatibility's sake. Too many existing programs use _
as a local variable (far too more than _1
).
We'd be happy to be proven wrong. If someone is willing to experiment and to find the solution to solve the compatibility problem, please reopen the issue.
Matz.
Could you please point us to an existing discussion or maybe show a few examples?
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0