Project

General

Profile

Feature #16939

Alias _1 as _ for block numbered params

Added by x3qt (Yury Polyakov) 7 months ago. Updated 7 months ago.

Status:
Closed
Priority:
Normal
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) 7 months 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) 7 months 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) 7 months 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 (Yury Polyakov) 7 months 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?

Also available in: Atom PDF