Project

General

Profile

Actions

Feature #16939

closed

Alias _1 as _ for block numbered params

Added by x3qt (Jury Paliakou) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:98678]

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.

Updated by shevegen (Robert A. Heiler) almost 4 years ago

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.]

Updated by matz (Yukihiro Matsumoto) almost 4 years ago

  • 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.

Updated by marcandre (Marc-Andre Lafortune) almost 4 years ago

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?

Updated by x3qt (Jury Paliakou) almost 4 years ago

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?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0