Project

General

Profile

Feature #10318

[PATCH 0/n] Let underscore be positionally matched arg to omit binding obvious variable.

Added by gogotanaka (Kazuki Tanaka) about 3 years ago. Updated about 3 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
[ruby-core:65373]

Description

I’m so sorry for just proposing this future without PATCH right now ...

(I suppose it contains too much issues.)

After some discussions, let me implement this future.

Of course I need to obtain your consent.

Anyway, I want to let underscore be positionally matched arg and omit to binding obvious variable when it comes to proc, lambda and block .

# let items be a Array of String. (e.g. items = ['foo', 'bar', 'foobar']

# Before
items.select { |item| item.include?('foo') }

# After
items.select { _.include?('foo') }

Even if block has more than 2 args, I want to omit one of them.

(I know it has much pain ... just idea)

# let nums be a Array of Integer. (e.g. nums = [1, 2, 3, 4]

# Before
nums.inject { |sum, num| sum + num }

# After
nums.inject { |sum| sum + _ }
#↑ It seems to difficult to hundle .. but looks aesthetic or understandable.

Let me know how do you think about it or what problem is.

thank you. gogo.

convert_tabs_to_spaces.patch (29.3 KB) convert_tabs_to_spaces.patch gogotanaka (Kazuki Tanaka), 10/05/2014 10:46 PM

History

#2 Updated by sawa (Tsuyoshi Sawada) about 3 years ago

When there is more than one parameter passed to a block, your proposal will create a problem.

When the number of parameters passed to a block is more than the number of block variables in ||, then destructive assignment should apply, but your proposal will make this not happen. It will be incompatible with many existing code.

#3 [ruby-core:65432] Updated by nobu (Nobuyoshi Nakada) about 3 years ago

Why expanding tabs?

#4 [ruby-core:65433] Updated by gogotanaka (Kazuki Tanaka) about 3 years ago

@Tsuyoshi Sawada san

Thank you for your comment. I got your point.

As you said (and I mentioned also) it has much pain, so I can't implement right now.

How do you think about the case giving a argument?

I mean like that.

['foo', 'bar', 'foobar'].select { _.include?('foo') }
['foo', 'bar', 'foobar'].each { eval(_) }

#5 [ruby-core:65435] Updated by gogotanaka (Kazuki Tanaka) about 3 years ago

@Nobuyoshi Nakada san

Thank you for your comment.

Starting to implement this issue, I find spaces and tabs being mixed.

And I suppose this might make us confusion and there are no reason spaces and tabs be mixed, but I am afraid a conflict.

This is why I upload this patch at first.

#6 [ruby-core:65437] Updated by nobu (Nobuyoshi Nakada) about 3 years ago

Welcome to the underground holy war. ;)
You may know that ruby-style.el has (indent-tabs-mode . t).

#7 [ruby-core:65445] Updated by gogotanaka (Kazuki Tanaka) about 3 years ago

@Nobuyoshi Nakada san

It was an honor to encounter such a underground holy war.

Sure. I'll follow what you said.

Thank you.

#8 [ruby-core:66106] Updated by gogotanaka (Kazuki Tanaka) about 3 years ago

oops... I found totally incompatible code in Rails project.
I gave up this approach. Nonetheless, I still wanna introduce concept omitting obvious variable. (Like Scala's lambda calculus)
#10394 does make sense so far?

Also available in: Atom PDF