ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:95486] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method"
       [not found] <redmine.issue-16273.20191023004736@ruby-lang.org>
@ 2019-10-23  0:47 ` manga.osyo
  2019-10-23  6:45 ` [ruby-core:95490] " nobu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: manga.osyo @ 2019-10-23  0:47 UTC (permalink / raw)
  To: ruby-core

Issue #16273 has been reported by osyo (manga osyo).

----------------------------------------
Feature #16273: Proposal: Shorthand operator for "#instance_method"
https://bugs.ruby-lang.org/issues/16273

* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
hi, created issues to discuss shorthand for "#instance_method"

## Overview

Ruby 2.7 adds a `#method` shorthand `.:` operator.

* [Feature #12125: Proposal: Shorthand operator for Object#method - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/12125)
* [Feature #13581: Syntax sugar for method reference - CommonRuby - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/13581)

In this issues want to discuss the shorthand operator for "#instance_method".


## Background

If you want to pass an array to `Array#zip` or `Hash#merge` as shown below, the code will be messy.

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

# `#first` must be a receiver and the value excluding `#first` must be passed as an argument
arrays.first.zip(*arrays.drop(1))
arrays.first.product(*arrays.drop(1))
hashs.first.merge(*hashs.drop(1))
```

This can be solved by using `# bind_call` ([# 15955] (https://bugs.ruby-lang.org/issues/15955)).

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

Array.instance_method(:zip).bind_call(*arrays)
Array.instance_method(:product).bind_call(*arrays)
Hash.instance_method(:merge).bind_call(*hashs)
```

But `#instance_method` is long.
I'm thinking shorthand operator for `#instance_method`.

:MEMO: There was a suggestion to add `Array.zip` or `Array.product` in the past

* [Feature #8970: Array.zip and Array.product - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/8970)
* [Feature #6499: Array::zip - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/6499)
* [Feature #7444: Array#product_set - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/7444)

## Proposal new operator

I can't come up with a suitable operator yet, sorry...
However, considering the `.:` operator, I think "operator + Symbol (`:`)" is good.

```ruby
# Document-like writing
# `#` + operator
Array#zip
Array.#zip
Array#:zip

# Constant-link writing
# :: + :hoge
Array:::zip
Array::#zip
```

Also, the following syntax is valid at this time, so it may be difficult to adopt.

```ruby
Array!zip
Array@zip
Array&zip
Array:zip
```

Please comment if you are interested in the shorthand operator for `# instance_method`.

* Other `#instance_method` usecase
* Proposal shorthand operator
* etc...

Thank you! :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:95490] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method"
       [not found] <redmine.issue-16273.20191023004736@ruby-lang.org>
  2019-10-23  0:47 ` [ruby-core:95486] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method" manga.osyo
@ 2019-10-23  6:45 ` nobu
  2019-10-23  6:49 ` [ruby-core:95491] " naruse
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: nobu @ 2019-10-23  6:45 UTC (permalink / raw)
  To: ruby-core

Issue #16273 has been updated by nobu (Nobuyoshi Nakada).


I don't think using `#` acceptable, and have thought `.::`.

----------------------------------------
Feature #16273: Proposal: Shorthand operator for "#instance_method"
https://bugs.ruby-lang.org/issues/16273#change-82261

* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
hi, created issues to discuss shorthand for "#instance_method"

## Overview

Ruby 2.7 adds a `#method` shorthand `.:` operator.

* [Feature #12125: Proposal: Shorthand operator for Object#method - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/12125)
* [Feature #13581: Syntax sugar for method reference - CommonRuby - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/13581)

In this issues want to discuss the shorthand operator for "#instance_method".


## Background

If you want to pass an array to `Array#zip` or `Hash#merge` as shown below, the code will be messy.

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

# `#first` must be a receiver and the value excluding `#first` must be passed as an argument
arrays.first.zip(*arrays.drop(1))
arrays.first.product(*arrays.drop(1))
hashs.first.merge(*hashs.drop(1))
```

This can be solved by using `# bind_call` ([# 15955] (https://bugs.ruby-lang.org/issues/15955)).

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

Array.instance_method(:zip).bind_call(*arrays)
Array.instance_method(:product).bind_call(*arrays)
Hash.instance_method(:merge).bind_call(*hashs)
```

But `#instance_method` is long.
I'm thinking shorthand operator for `#instance_method`.

:MEMO: There was a suggestion to add `Array.zip` or `Array.product` in the past

* [Feature #8970: Array.zip and Array.product - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/8970)
* [Feature #6499: Array::zip - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/6499)
* [Feature #7444: Array#product_set - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/7444)

## Proposal new operator

I can't come up with a suitable operator yet, sorry...
However, considering the `.:` operator, I think "operator + Symbol (`:`)" is good.

```ruby
# Document-like writing
# `#` + operator
Array#zip
Array.#zip
Array#:zip

# Constant-link writing
# :: + :hoge
Array:::zip
Array::#zip
```

Also, the following syntax is valid at this time, so it may be difficult to adopt.

```ruby
Array!zip
Array@zip
Array&zip
Array:zip
```

Please comment if you are interested in the shorthand operator for `# instance_method`.

* Other `#instance_method` usecase
* Proposal shorthand operator
* etc...

Thank you! :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:95491] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method"
       [not found] <redmine.issue-16273.20191023004736@ruby-lang.org>
  2019-10-23  0:47 ` [ruby-core:95486] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method" manga.osyo
  2019-10-23  6:45 ` [ruby-core:95490] " nobu
@ 2019-10-23  6:49 ` naruse
  2019-10-23  7:12 ` [ruby-core:95492] " muraken
  2019-10-23  7:50 ` [ruby-core:95494] " zverok.offline
  4 siblings, 0 replies; 5+ messages in thread
From: naruse @ 2019-10-23  6:49 UTC (permalink / raw)
  To: ruby-core

Issue #16273 has been updated by naruse (Yui NARUSE).


I don't think `Array.instance_method(:zip).bind_call(*arrays)` should be recommended, and worth adding shorthand operator.

----------------------------------------
Feature #16273: Proposal: Shorthand operator for "#instance_method"
https://bugs.ruby-lang.org/issues/16273#change-82262

* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
hi, created issues to discuss shorthand for "#instance_method"

## Overview

Ruby 2.7 adds a `#method` shorthand `.:` operator.

* [Feature #12125: Proposal: Shorthand operator for Object#method - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/12125)
* [Feature #13581: Syntax sugar for method reference - CommonRuby - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/13581)

In this issues want to discuss the shorthand operator for "#instance_method".


## Background

If you want to pass an array to `Array#zip` or `Hash#merge` as shown below, the code will be messy.

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

# `#first` must be a receiver and the value excluding `#first` must be passed as an argument
arrays.first.zip(*arrays.drop(1))
arrays.first.product(*arrays.drop(1))
hashs.first.merge(*hashs.drop(1))
```

This can be solved by using `# bind_call` ([# 15955] (https://bugs.ruby-lang.org/issues/15955)).

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

Array.instance_method(:zip).bind_call(*arrays)
Array.instance_method(:product).bind_call(*arrays)
Hash.instance_method(:merge).bind_call(*hashs)
```

But `#instance_method` is long.
I'm thinking shorthand operator for `#instance_method`.

:MEMO: There was a suggestion to add `Array.zip` or `Array.product` in the past

* [Feature #8970: Array.zip and Array.product - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/8970)
* [Feature #6499: Array::zip - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/6499)
* [Feature #7444: Array#product_set - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/7444)

## Proposal new operator

I can't come up with a suitable operator yet, sorry...
However, considering the `.:` operator, I think "operator + Symbol (`:`)" is good.

```ruby
# Document-like writing
# `#` + operator
Array#zip
Array.#zip
Array#:zip

# Constant-link writing
# :: + :hoge
Array:::zip
Array::#zip
```

Also, the following syntax is valid at this time, so it may be difficult to adopt.

```ruby
Array!zip
Array@zip
Array&zip
Array:zip
```

Please comment if you are interested in the shorthand operator for `# instance_method`.

* Other `#instance_method` usecase
* Proposal shorthand operator
* etc...

Thank you! :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:95492] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method"
       [not found] <redmine.issue-16273.20191023004736@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-10-23  6:49 ` [ruby-core:95491] " naruse
@ 2019-10-23  7:12 ` muraken
  2019-10-23  7:50 ` [ruby-core:95494] " zverok.offline
  4 siblings, 0 replies; 5+ messages in thread
From: muraken @ 2019-10-23  7:12 UTC (permalink / raw)
  To: ruby-core

Issue #16273 has been updated by mrkn (Kenta Murata).


I don't think the first examples are messy.
On the contrary, the second examples using `bind_call` are quite messy than the first.

----------------------------------------
Feature #16273: Proposal: Shorthand operator for "#instance_method"
https://bugs.ruby-lang.org/issues/16273#change-82263

* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
hi, created issues to discuss shorthand for "#instance_method"

## Overview

Ruby 2.7 adds a `#method` shorthand `.:` operator.

* [Feature #12125: Proposal: Shorthand operator for Object#method - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/12125)
* [Feature #13581: Syntax sugar for method reference - CommonRuby - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/13581)

In this issues want to discuss the shorthand operator for "#instance_method".


## Background

If you want to pass an array to `Array#zip` or `Hash#merge` as shown below, the code will be messy.

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

# `#first` must be a receiver and the value excluding `#first` must be passed as an argument
arrays.first.zip(*arrays.drop(1))
arrays.first.product(*arrays.drop(1))
hashs.first.merge(*hashs.drop(1))
```

This can be solved by using `# bind_call` ([# 15955] (https://bugs.ruby-lang.org/issues/15955)).

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

Array.instance_method(:zip).bind_call(*arrays)
Array.instance_method(:product).bind_call(*arrays)
Hash.instance_method(:merge).bind_call(*hashs)
```

But `#instance_method` is long.
I'm thinking shorthand operator for `#instance_method`.

:MEMO: There was a suggestion to add `Array.zip` or `Array.product` in the past

* [Feature #8970: Array.zip and Array.product - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/8970)
* [Feature #6499: Array::zip - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/6499)
* [Feature #7444: Array#product_set - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/7444)

## Proposal new operator

I can't come up with a suitable operator yet, sorry...
However, considering the `.:` operator, I think "operator + Symbol (`:`)" is good.

```ruby
# Document-like writing
# `#` + operator
Array#zip
Array.#zip
Array#:zip

# Constant-link writing
# :: + :hoge
Array:::zip
Array::#zip
```

Also, the following syntax is valid at this time, so it may be difficult to adopt.

```ruby
Array!zip
Array@zip
Array&zip
Array:zip
```

Please comment if you are interested in the shorthand operator for `# instance_method`.

* Other `#instance_method` usecase
* Proposal shorthand operator
* etc...

Thank you! :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:95494] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method"
       [not found] <redmine.issue-16273.20191023004736@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-10-23  7:12 ` [ruby-core:95492] " muraken
@ 2019-10-23  7:50 ` zverok.offline
  4 siblings, 0 replies; 5+ messages in thread
From: zverok.offline @ 2019-10-23  7:50 UTC (permalink / raw)
  To: ruby-core

Issue #16273 has been updated by zverok (Victor Shepelev).


Funnily enough (and not completely intentionally) the problem is "solved" with #16264:

```ruby
.:zip.call(*arrays)
# or even... for those who likes to cry "code golf!"
.:zip.(*arrays)
```
Currently, you also can
```ruby
:zip.to_proc.call(*arrays)
```

Though, I tend to agree with @mrkn that "no-tricks" first example looks pretty clear... But I understand that in codebase where this metaphor emerges regularly, it could become tiresome and too non-atomic to read.

One another non-orthodox suggestion (which uses `#then` loathed by some, but of all the rest of examples the only one which reads directly "zip first array with the rest of them"):
```ruby
arrays.then { |first, *rest| first.zip(*rest) }
```

----------------------------------------
Feature #16273: Proposal: Shorthand operator for "#instance_method"
https://bugs.ruby-lang.org/issues/16273#change-82265

* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
hi, created issues to discuss shorthand for "#instance_method"

## Overview

Ruby 2.7 adds a `#method` shorthand `.:` operator.

* [Feature #12125: Proposal: Shorthand operator for Object#method - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/12125)
* [Feature #13581: Syntax sugar for method reference - CommonRuby - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/13581)

In this issues want to discuss the shorthand operator for "#instance_method".


## Background

If you want to pass an array to `Array#zip` or `Hash#merge` as shown below, the code will be messy.

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

# `#first` must be a receiver and the value excluding `#first` must be passed as an argument
arrays.first.zip(*arrays.drop(1))
arrays.first.product(*arrays.drop(1))
hashs.first.merge(*hashs.drop(1))
```

This can be solved by using `# bind_call` ([# 15955] (https://bugs.ruby-lang.org/issues/15955)).

```ruby
arrays = [["a", "b"], ["c"], ["d", "e"]]
hashs  = [{"a" => 1}, {"b" => 2, "c" => 3}, {"d" => 4, "e" => 5}]

Array.instance_method(:zip).bind_call(*arrays)
Array.instance_method(:product).bind_call(*arrays)
Hash.instance_method(:merge).bind_call(*hashs)
```

But `#instance_method` is long.
I'm thinking shorthand operator for `#instance_method`.

:MEMO: There was a suggestion to add `Array.zip` or `Array.product` in the past

* [Feature #8970: Array.zip and Array.product - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/8970)
* [Feature #6499: Array::zip - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/6499)
* [Feature #7444: Array#product_set - Ruby master - Ruby Issue Tracking System](https://bugs.ruby-lang.org/issues/7444)

## Proposal new operator

I can't come up with a suitable operator yet, sorry...
However, considering the `.:` operator, I think "operator + Symbol (`:`)" is good.

```ruby
# Document-like writing
# `#` + operator
Array#zip
Array.#zip
Array#:zip

# Constant-link writing
# :: + :hoge
Array:::zip
Array::#zip
```

Also, the following syntax is valid at this time, so it may be difficult to adopt.

```ruby
Array!zip
Array@zip
Array&zip
Array:zip
```

Please comment if you are interested in the shorthand operator for `# instance_method`.

* Other `#instance_method` usecase
* Proposal shorthand operator
* etc...

Thank you! :)




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-23  7:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-16273.20191023004736@ruby-lang.org>
2019-10-23  0:47 ` [ruby-core:95486] [Ruby master Feature#16273] Proposal: Shorthand operator for "#instance_method" manga.osyo
2019-10-23  6:45 ` [ruby-core:95490] " nobu
2019-10-23  6:49 ` [ruby-core:95491] " naruse
2019-10-23  7:12 ` [ruby-core:95492] " muraken
2019-10-23  7:50 ` [ruby-core:95494] " zverok.offline

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).