ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:94342] [Ruby master Feature#16102] `Symbol#call`
       [not found] <redmine.issue-16102.20190814065946@ruby-lang.org>
@ 2019-08-14  6:59 ` sawadatsuyoshi
  2019-08-14  7:00 ` [ruby-core:94343] " sawadatsuyoshi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: sawadatsuyoshi @ 2019-08-14  6:59 UTC (permalink / raw)
  To: ruby-core

Issue #16102 has been reported by sawa (Tsuyoshi Sawada).

----------------------------------------
Feature #16102: `Symbol#call`
https://bugs.ruby-lang.org/issues/16102

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Since symbols have a `to_proc` method, it is natural to expect that they would appear in a method chain like:

```ruby
:some_symbol.to_proc.call(...)
```

In fact, I have use cases like this:

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

:product.to_proc.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.to_proc.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.to_proc.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.to_proc.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

I request `Symbol#call` to be defined, which would implicitly call `to_proc` on the receiver and then the conventional `Proc#call` on the result. Then, I can do:

```ruby
:product.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

Notice that proposals #12115 and #15301 ask for `Symbol#call`, but they ask for different things (a method that returns a proc), and are irrelevant to the current proposal.



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

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

* [ruby-core:94343] [Ruby master Feature#16102] `Symbol#call`
       [not found] <redmine.issue-16102.20190814065946@ruby-lang.org>
  2019-08-14  6:59 ` [ruby-core:94342] [Ruby master Feature#16102] `Symbol#call` sawadatsuyoshi
@ 2019-08-14  7:00 ` sawadatsuyoshi
  2019-08-14  8:37 ` [ruby-core:94345] " shevegen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: sawadatsuyoshi @ 2019-08-14  7:00 UTC (permalink / raw)
  To: ruby-core

Issue #16102 has been updated by sawa (Tsuyoshi Sawada).


Related to #11262.

----------------------------------------
Feature #16102: `Symbol#call`
https://bugs.ruby-lang.org/issues/16102#change-80742

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Since symbols have a `to_proc` method, it is natural to expect that they would appear in a method chain like:

```ruby
:some_symbol.to_proc.call(...)
```

In fact, I have use cases like this:

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

:product.to_proc.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.to_proc.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.to_proc.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.to_proc.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

I request `Symbol#call` to be defined, which would implicitly call `to_proc` on the receiver and then the conventional `Proc#call` on the result. Then, I can do:

```ruby
:product.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

Notice that proposals #12115 and #15301 ask for `Symbol#call`, but they ask for different things (a method that returns a proc), and are irrelevant to the current proposal.



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

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

* [ruby-core:94345] [Ruby master Feature#16102] `Symbol#call`
       [not found] <redmine.issue-16102.20190814065946@ruby-lang.org>
  2019-08-14  6:59 ` [ruby-core:94342] [Ruby master Feature#16102] `Symbol#call` sawadatsuyoshi
  2019-08-14  7:00 ` [ruby-core:94343] " sawadatsuyoshi
@ 2019-08-14  8:37 ` shevegen
  2019-08-14  9:00 ` [ruby-core:94347] " mame
  2019-09-12  9:25 ` [ruby-core:94920] " joshua.goodall
  4 siblings, 0 replies; 5+ messages in thread
From: shevegen @ 2019-08-14  8:37 UTC (permalink / raw)
  To: ruby-core

Issue #16102 has been updated by shevegen (Robert A. Heiler).


I have no particular pro/con opinion on the suggested functionality here itself.

In my opinion, this is mostly a design consideration for how "useful" matz
wants to see symbols being used in ruby. (This may not be directly related
to the comment here, but more generally in how simple, complex or useful
matz may want to see symbols.)

On a side note, it is (to me) interesting that sawa is not the only one
with somewhat related ideas in this regard, as he has pointed out via
mentioning https://bugs.ruby-lang.org/issues/12115. :)

----------------------------------------
Feature #16102: `Symbol#call`
https://bugs.ruby-lang.org/issues/16102#change-80748

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Since symbols have a `to_proc` method, it is natural to expect that they would appear in a method chain like:

```ruby
:some_symbol.to_proc.call(...)
```

In fact, I have use cases like this:

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

:product.to_proc.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.to_proc.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.to_proc.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.to_proc.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

I request `Symbol#call` to be defined, which would implicitly call `to_proc` on the receiver and then the conventional `Proc#call` on the result. Then, I can do:

```ruby
:product.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

This would solve what proposals #6499, #6727, #7444, #8970, #11262 aim to do.

Notice that proposals #12115 and #15301 ask for `Symbol#call`, but they ask for different things (a method that returns a proc), and are irrelevant to the current proposal.



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

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

* [ruby-core:94347] [Ruby master Feature#16102] `Symbol#call`
       [not found] <redmine.issue-16102.20190814065946@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-08-14  8:37 ` [ruby-core:94345] " shevegen
@ 2019-08-14  9:00 ` mame
  2019-09-12  9:25 ` [ruby-core:94920] " joshua.goodall
  4 siblings, 0 replies; 5+ messages in thread
From: mame @ 2019-08-14  9:00 UTC (permalink / raw)
  To: ruby-core

Issue #16102 has been updated by mame (Yusuke Endoh).


I agree that `ary1.zip(ary2, ary3)` is asymmetric and uncool, but I don't like solving the issue by adding a method of Symbol.  `:zip.(*arrays)` looks too cryptic and semantically hacky to me.  Rather, I like your #8970: `Array.zip(ary1, ary2, ary3)`.  It is much simpler, clearer, and easier to understand.  

----------------------------------------
Feature #16102: `Symbol#call`
https://bugs.ruby-lang.org/issues/16102#change-80750

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Since symbols have a `to_proc` method, it is natural to expect that they would appear in a method chain like:

```ruby
:some_symbol.to_proc.call(...)
```

In fact, I have use cases like this:

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

:product.to_proc.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.to_proc.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.to_proc.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.to_proc.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

I request `Symbol#call` to be defined, which would implicitly call `to_proc` on the receiver and then the conventional `Proc#call` on the result. Then, I can do:

```ruby
:product.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

This would solve what proposals #6499, #6727, #7444, #8970, #11262 aim to do.

Notice that proposals #12115 and #15301 ask for `Symbol#call`, but they ask for different things (a method that returns a proc), and are irrelevant to the current proposal.



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

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

* [ruby-core:94920] [Ruby master Feature#16102] `Symbol#call`
       [not found] <redmine.issue-16102.20190814065946@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-08-14  9:00 ` [ruby-core:94347] " mame
@ 2019-09-12  9:25 ` joshua.goodall
  4 siblings, 0 replies; 5+ messages in thread
From: joshua.goodall @ 2019-09-12  9:25 UTC (permalink / raw)
  To: ruby-core

Issue #16102 has been updated by inopinatus (Joshua GOODALL).


I propose this general solution.

    diff --git a/array.c b/array.c
    index 3717c3ff34..3809af01cf 100644
    --- a/array.c
    +++ b/array.c
    @@ -6988,6 +6988,7 @@ Init_Array(void)
         rb_define_method(rb_cArray, "dig", rb_ary_dig, -1);
         rb_define_method(rb_cArray, "sum", rb_ary_sum, -1);
     
    +    rb_define_method(rb_cArray, "splat", rb_yield_splat, 0);
         rb_define_method(rb_cArray, "deconstruct", rb_ary_deconstruct, 0);
     
         id_random = rb_intern("random");

then:

    arrays = [["a", "b"], ["c"], ["d", "e"]]

    arrays.splat(&:product)
    #=> [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]


----------------------------------------
Feature #16102: `Symbol#call`
https://bugs.ruby-lang.org/issues/16102#change-81534

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Since symbols have a `to_proc` method, it is natural to expect that they would appear in a method chain like:

```ruby
:some_symbol.to_proc.call(...)
```

In fact, I have use cases like this:

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

:product.to_proc.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.to_proc.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.to_proc.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.to_proc.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

I request `Symbol#call` to be defined, which would implicitly call `to_proc` on the receiver and then the conventional `Proc#call` on the result. Then, I can do:

```ruby
:product.(*arrays) # => [["a", "c", "d"], ["a", "c", "e"], ["b", "c", "d"], ["b", "c", "e"]]
:zip.(*arrays) # => [["a", "c", "d"], ["b", nil, "e"]]
:union.(*arrays) # => ["a", "b", "c", "d", "e"]
:merge.(*hashes) # => {"a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5}
```

This would solve what proposals #6499, #6727, #7444, #8970, #11262 aim to do.

Notice that proposals #12115 and #15301 ask for `Symbol#call`, but they ask for different things (a method that returns a proc), and are irrelevant to the current proposal.



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

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

end of thread, other threads:[~2019-09-12  9:25 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-16102.20190814065946@ruby-lang.org>
2019-08-14  6:59 ` [ruby-core:94342] [Ruby master Feature#16102] `Symbol#call` sawadatsuyoshi
2019-08-14  7:00 ` [ruby-core:94343] " sawadatsuyoshi
2019-08-14  8:37 ` [ruby-core:94345] " shevegen
2019-08-14  9:00 ` [ruby-core:94347] " mame
2019-09-12  9:25 ` [ruby-core:94920] " joshua.goodall

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