Project

General

Profile

Actions

Feature #10318

open

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

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

Status:
Open
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.


Files

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

Updated by sawa (Tsuyoshi Sawada) about 10 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.

Updated by nobu (Nobuyoshi Nakada) about 10 years ago

Why expanding tabs?

Updated by gogotanaka (Kazuki Tanaka) about 10 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(_) }

Updated by gogotanaka (Kazuki Tanaka) about 10 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.

Updated by nobu (Nobuyoshi Nakada) about 10 years ago

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

Updated by gogotanaka (Kazuki Tanaka) about 10 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.

Updated by gogotanaka (Kazuki Tanaka) about 10 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?

Actions #9

Updated by naruse (Yui NARUSE) about 4 years ago

  • Target version deleted (3.0)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0