ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:74036] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
@ 2016-02-28 21:39 ` Stefan-Merettig
  2016-02-28 21:43 ` [ruby-core:74037] " Stefan-Merettig
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Stefan-Merettig @ 2016-02-28 21:39 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been reported by Stefan Merettig.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74037] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
  2016-02-28 21:39 ` [ruby-core:74036] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method Stefan-Merettig
@ 2016-02-28 21:43 ` Stefan-Merettig
  2016-02-29  0:37 ` [ruby-core:74038] " matz
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Stefan-Merettig @ 2016-02-28 21:43 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Stefan Merettig.


> The & operator lets one pass a #call-able object as block.

I meant `#to_proc`-able objects, sorry for the confusion.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57192

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74038] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
  2016-02-28 21:39 ` [ruby-core:74036] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method Stefan-Merettig
  2016-02-28 21:43 ` [ruby-core:74037] " Stefan-Merettig
@ 2016-02-29  0:37 ` matz
  2016-02-29 12:58 ` [ruby-core:74050] " zverok.offline
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: matz @ 2016-02-29  0:37 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Yukihiro Matsumoto.


I like the idea of short hand notation for `Object#method()`, but I don't think `->` is a good idea.

Matz.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57193

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74050] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2016-02-29  0:37 ` [ruby-core:74038] " matz
@ 2016-02-29 12:58 ` zverok.offline
  2016-02-29 14:14 ` [ruby-core:74053] " Stefan-Merettig
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: zverok.offline @ 2016-02-29 12:58 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Victor Shepelev.


For this kind of "conceptual" methods I sometimes define just one-letter shortcuts in core_ext.rb, like `.map(&File.m(:basename))`. I'm not sure, though, if any of existing/popular libraries will struggle from such kind of solution (or may be it would not play really well with local variables, which are frequently have one-letter names).

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57205

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74053] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2016-02-29 12:58 ` [ruby-core:74050] " zverok.offline
@ 2016-02-29 14:14 ` Stefan-Merettig
  2016-02-29 14:29 ` [ruby-core:74055] " co000ri
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Stefan-Merettig @ 2016-02-29 14:14 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Stefan Merettig.


Yukihiro Matsumoto wrote:
> but I don't think `->` is a good idea.

Other options I can think of are:

* Using `.>`: `the_object.>a_method`  While its look is nearer to a normal method call (Which I think is a plus), I fear that the period would be hard to see in some fonts. Another plus is that this would be a entirely new operator, so no (unintentional?) breaking changes in the parser.
* Using `<..>`: `the_object<a_method>`  Inspired by the look of generics/templates in other programming languages. Should not clash with existing code and parsers and is well-readable in fonts I guess. Maybe it doesn't read as well anymore though, and the intention of `<..>` may not be that clear at first to someone who doesn't know the syntax (yet). No idea if that is a concern.
* Using `&>`: `the_object&>a_method`  Also readable in any font I can think of. It's a spin on `&.`, reading like "and this"
* Using `|>`: `the_object|>a_method`  I think the *Elixir* language has this operator too (albeit with other semantics?). Its read like "and pipe it through this", so maybe it reads a bit like a shell script too?

Regards,
Stefan

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57207

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74055] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2016-02-29 14:14 ` [ruby-core:74053] " Stefan-Merettig
@ 2016-02-29 14:29 ` co000ri
  2016-02-29 16:40 ` [ruby-core:74056] " funny.falcon
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: co000ri @ 2016-02-29 14:29 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Yuki Kurihara.


How about this one?

~~~ruby
File.method #=> #<UnfoundMethod receiver=File>
File.method.basename #=> #<Method: File.basename>
Dir["*/*.c"].map(&File.method.basename) #=> ["foo.c", "bar.c"]
~~~

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57208

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74056] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2016-02-29 14:29 ` [ruby-core:74055] " co000ri
@ 2016-02-29 16:40 ` funny.falcon
  2016-02-29 20:40 ` [ruby-core:74064] " shevegen
                   ` (17 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: funny.falcon @ 2016-02-29 16:40 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Yura Sokolov.


Please don't do this!!! No need to make the language more complex just to solve such small issue!!!

If you want to do something pretty, then whole closure syntax should be simplified, not just call to '#method'.

````ruby
Dir["*/*.c"].map{File.basename(_0)} # where `_0` is magic var
````
Then bytecode compiler may optimize it to `.map(&File.method(:basename))`

But it then allows to do more pretty things, for example:

````ruby
# dumps key=>value pairs
myhash.each{|k,v| puts "#{k}=>#{v}"}
# do it in shorter way
myhash.each{puts "#{_0}=>#{_1}"}
````

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57209

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74064] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2016-02-29 16:40 ` [ruby-core:74056] " funny.falcon
@ 2016-02-29 20:40 ` shevegen
  2016-03-01  2:23 ` [ruby-core:74072] " nobu
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: shevegen @ 2016-02-29 20:40 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Robert A. Heiler.


I think the &File->basename looks confusing since we also have
-> standalone now.

object->method reminds me a lot of php/perl and ruby uses the
prettier . instead, object.method.

I also think that :

.map{File.basename(_0)} # where `_0` is magic var

Is not good either. I like _ as a variable name a lot but on
its own, not with extra. :)

Yuki Kurihara's proposal is somewhat better as he does not 
have to use special constructs/tokens.

Dir["*/*.c"].map(&File.method.basename)

I believe that crystal allows some parameter for &; and I think
there have been earlier proposals in ruby too.

> But I think it makes sense: You have an object, and from that
> object you point at a method to get it as Method.

I do not think that this argument is a good one because the ->
is used in a dissimilar way, akin to Proc.new / lambda, 
whereas your syntax proposal would be more similar to php
and perl syntax style, which I think will be confusing in
addition to -> already having another method. So this is 
not good in my opinion.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57216

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74072] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2016-02-29 20:40 ` [ruby-core:74064] " shevegen
@ 2016-03-01  2:23 ` nobu
  2016-03-01  2:24 ` [ruby-core:74073] " nobu
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: nobu @ 2016-03-01  2:23 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Nobuyoshi Nakada.


Stefan Merettig wrote:
> * Using `.>`: `the_object.>a_method`
> * Using `<..>`: `the_object<a_method>`

These two conflict with existing syntax and break compatibility.
Note that `object.>(other)` is a valid method call.


----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57223

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

`Dir["*/*.c"].map(&File.method(:basename))`

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an Object.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74073] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (8 preceding siblings ...)
  2016-03-01  2:23 ` [ruby-core:74072] " nobu
@ 2016-03-01  2:24 ` nobu
  2016-03-14  1:42 ` [ruby-core:74293] " Ruby-Lang
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: nobu @ 2016-03-01  2:24 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Nobuyoshi Nakada.

Description updated

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57224

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74293] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (9 preceding siblings ...)
  2016-03-01  2:24 ` [ruby-core:74073] " nobu
@ 2016-03-14  1:42 ` Ruby-Lang
  2016-03-14  1:44 ` [ruby-core:74294] " Ruby-Lang
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Ruby-Lang @ 2016-03-14  1:42 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Jörg W Mittag.


A proposal that has existed for years, if not decades, is to deprecate usage of the `::` double colon binary infix namespace operator for message sends, and instead re-use it for method references:

~~~ruby
Dir["*/*.c"].map(&File::basename)
~~~

This is also the syntax chosen by Java for method references.

There is one big problem, though: ambiguity with constant references for methods which start with an uppercase letter. Maybe, it would be possible to require parentheses in that case?

~~~ruby
%w[1 2 3].map(&::Integer())
~~~

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57415

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74294] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (10 preceding siblings ...)
  2016-03-14  1:42 ` [ruby-core:74293] " Ruby-Lang
@ 2016-03-14  1:44 ` Ruby-Lang
  2016-03-14 16:46 ` [ruby-core:74299] " mame
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Ruby-Lang @ 2016-03-14  1:44 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Jörg W Mittag.


It would be nice if we could find symmetric syntax for getting an `UnboundMethod` from a module.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57416

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)


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

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

* [ruby-core:74299] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (11 preceding siblings ...)
  2016-03-14  1:44 ` [ruby-core:74294] " Ruby-Lang
@ 2016-03-14 16:46 ` mame
  2016-03-15  1:35 ` [ruby-core:74317] " nobu
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: mame @ 2016-03-14 16:46 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Yusuke Endoh.

File dot-symbol.patch added

+1 for this proposal.  How about `recv.:fname`?

~~~
$ ./miniruby -e 'p Dir["*/*.c"].map(&File.:basename)'
["hypot.c", "memcmp.c", "erf.c", ...]
~~~

Fortunately, it brings no conflict.

A patch is attached.  (dot-symbol.patch)

-- 
Yusuke Endoh <mame@ruby-lang.org>

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57419

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74317] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (12 preceding siblings ...)
  2016-03-14 16:46 ` [ruby-core:74299] " mame
@ 2016-03-15  1:35 ` nobu
  2016-03-15  3:41 ` [ruby-core:74323] " mame
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: nobu @ 2016-03-15  1:35 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Nobuyoshi Nakada.


Yusuke Endoh wrote:
> +1 for this proposal.  How about `recv.:fname`?

`dot_or_colon` means that `File:::basename` also works?

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57436

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74323] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (13 preceding siblings ...)
  2016-03-15  1:35 ` [ruby-core:74317] " nobu
@ 2016-03-15  3:41 ` mame
  2016-03-15 19:56 ` [ruby-core:74352] " Stefan-Merettig
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: mame @ 2016-03-15  3:41 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Yusuke Endoh.


Nobuyoshi Nakada wrote:
> Yusuke Endoh wrote:
> > +1 for this proposal.  How about `recv.:fname`?
> 
> `dot_or_colon` means that `File:::basename` also works?

Yes it works.  But I don't think it is important.  Only `.:` is also okay to me.

-- 
Yusuke Endoh <mame@ruby-lang.org>

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57443

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74352] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (14 preceding siblings ...)
  2016-03-15  3:41 ` [ruby-core:74323] " mame
@ 2016-03-15 19:56 ` Stefan-Merettig
  2016-03-15 20:06 ` [ruby-core:74353] " funny.falcon
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: Stefan-Merettig @ 2016-03-15 19:56 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Stefan Merettig.


Yusuke Endoh wrote:
> Nobuyoshi Nakada wrote:
> > Yusuke Endoh wrote:
> > > +1 for this proposal.  How about `recv.:fname`?
> > 
> > `dot_or_colon` means that `File:::basename` also works?
> 
> Yes it works.  But I don't think it is important.  Only `.:` is also okay to me.

The tetris-operator `.:` makes sense to me, but in respect to `:::` I don't think we should allow "alternative" operators to do the same thing.



----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57472

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74353] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (15 preceding siblings ...)
  2016-03-15 19:56 ` [ruby-core:74352] " Stefan-Merettig
@ 2016-03-15 20:06 ` funny.falcon
  2016-03-16  8:57 ` [ruby-core:74368] " hanachin
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: funny.falcon @ 2016-03-15 20:06 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Yura Sokolov.


-1000

Please, don't!!!

I don't wonna Ruby to become Perl!!!

No more unnecessary syntax!!!

You all are not so weak! you are strong humans!!

You just can type a bit more characters!!!

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57473

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74368] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (16 preceding siblings ...)
  2016-03-15 20:06 ` [ruby-core:74353] " funny.falcon
@ 2016-03-16  8:57 ` hanachin
  2016-03-17  6:07 ` [ruby-core:74396] " shyouhei
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: hanachin @ 2016-03-16  8:57 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Seiei Miyagi.


How about `File[.basename]` ?

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57488

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74396] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (17 preceding siblings ...)
  2016-03-16  8:57 ` [ruby-core:74368] " hanachin
@ 2016-03-17  6:07 ` shyouhei
  2016-03-17  7:48 ` [ruby-core:74402] " nobu
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: shyouhei @ 2016-03-17  6:07 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Shyouhei Urabe.


Just a status update: I heard from Matz in this month's developer meeting that however he wants this, all proposed syntax so far didn't charm him.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57517

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74402] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (18 preceding siblings ...)
  2016-03-17  6:07 ` [ruby-core:74396] " shyouhei
@ 2016-03-17  7:48 ` nobu
  2016-03-17 19:52 ` [ruby-core:74439] " rpc
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: nobu @ 2016-03-17  7:48 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by Nobuyoshi Nakada.


Seiei Miyagi wrote:
> How about `File[.basename]` ?

It causes confusion if the receiver has `#[]` method.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57526

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74439] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (19 preceding siblings ...)
  2016-03-17  7:48 ` [ruby-core:74402] " nobu
@ 2016-03-17 19:52 ` rpc
  2016-03-17 20:53 ` [ruby-core:74440] " rpc
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 26+ messages in thread
From: rpc @ 2016-03-17 19:52 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by RP C.


Stefan Merettig wrote:
> Hello,
> 
> The `&` operator lets one pass a `#call`-able object as block.
> 
> Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:
> 
> ```ruby
> Dir["*/*.c"].map(&File.method(:basename))
> ```
> 
> More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.
> 
> Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.
> 
> It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`
> 
> I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
> and from that object you point at a method to get it as `Method`.
> 
> With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`
> 
> I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
> Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
> days.
> 
> Thank you for reading,
> Stefan.

Dir["*/*.c"].map(File[&:basename])

From File, employ basename method.  The referencing & should be applied to the method, not the class, as it is really the method you're concerned with. I'm not a language designer, but this is how I would *expect* this to work by looking at it.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57559

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74440] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (20 preceding siblings ...)
  2016-03-17 19:52 ` [ruby-core:74439] " rpc
@ 2016-03-17 20:53 ` rpc
  2016-03-17 21:22   ` [ruby-core:74441] " Matthew Kerwin
  2017-09-28 12:07 ` [ruby-core:83043] " vassilevsky
                   ` (2 subsequent siblings)
  24 siblings, 1 reply; 26+ messages in thread
From: rpc @ 2016-03-17 20:53 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by RP C.


Another thought: Dir["/.c"].map(File.&basename)

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57560

* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:74441] Re: [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
  2016-03-17 20:53 ` [ruby-core:74440] " rpc
@ 2016-03-17 21:22   ` Matthew Kerwin
  0 siblings, 0 replies; 26+ messages in thread
From: Matthew Kerwin @ 2016-03-17 21:22 UTC (permalink / raw
  To: Ruby developers


[-- Attachment #1.1: Type: text/plain, Size: 323 bytes --]

On 18/03/2016 6:54 AM, <rpc@bewitching.me> wrote:
>
> Issue #12125 has been updated by RP C.
>
> Another thought: Dir["/.c"].map(File.&basename)
>

Can someone please tell me what's wrong with

~~~ruby
Dir["/.c"].map{|f| File.basename f }
~~~

?

There's being concise, and there's syntax sugar, but this is getting silly.

[-- Attachment #1.2: Type: text/html, Size: 533 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]


Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

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

* [ruby-core:83043] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (21 preceding siblings ...)
  2016-03-17 20:53 ` [ruby-core:74440] " rpc
@ 2017-09-28 12:07 ` vassilevsky
  2017-09-28 13:23 ` [ruby-core:83044] " nobu
  2017-09-28 13:32 ` [ruby-core:83045] " nobu
  24 siblings, 0 replies; 26+ messages in thread
From: vassilevsky @ 2017-09-28 12:07 UTC (permalink / raw
  To: ruby-core

Issue #12125 has been updated by vassilevsky (Ilya Vassilevsky).


Is it possible to use a single colon for this?

    object:name

    File:basename

    URI:parse

As far as I can see (not far, really, I don't even know C), it is currently not used for anything.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-66965

* Author: Papierkorb (Stefan Merettig)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:83044] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (22 preceding siblings ...)
  2017-09-28 12:07 ` [ruby-core:83043] " vassilevsky
@ 2017-09-28 13:23 ` nobu
  2017-09-28 13:32 ` [ruby-core:83045] " nobu
  24 siblings, 0 replies; 26+ messages in thread
From: nobu @ 2017-09-28 13:23 UTC (permalink / raw
  To: ruby-core

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


A colon does too many things already, a ternary operator, a symbol literal, and a keyword argument.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-66966

* Author: Papierkorb (Stefan Merettig)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

* [ruby-core:83045] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method
       [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
                   ` (23 preceding siblings ...)
  2017-09-28 13:23 ` [ruby-core:83044] " nobu
@ 2017-09-28 13:32 ` nobu
  24 siblings, 0 replies; 26+ messages in thread
From: nobu @ 2017-09-28 13:32 UTC (permalink / raw
  To: ruby-core

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


`File[&:basename]` and `File.&basename` are valid syntax already.

----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-66967

* Author: Papierkorb (Stefan Merettig)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,

The `&` operator lets one pass a `#call`-able object as block.

Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:

```ruby
Dir["*/*.c"].map(&File.method(:basename))
```

More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.

Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.

It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`

I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.

With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`

I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.

Thank you for reading,
Stefan.

---Files--------------------------------
method_shorthand.diff (740 Bytes)
dot-symbol.patch (554 Bytes)


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

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

end of thread, other threads:[~2017-09-28 13:32 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-12125.20160228213954@ruby-lang.org>
2016-02-28 21:39 ` [ruby-core:74036] [Ruby trunk Feature#12125] Proposal: Shorthand operator for Object#method Stefan-Merettig
2016-02-28 21:43 ` [ruby-core:74037] " Stefan-Merettig
2016-02-29  0:37 ` [ruby-core:74038] " matz
2016-02-29 12:58 ` [ruby-core:74050] " zverok.offline
2016-02-29 14:14 ` [ruby-core:74053] " Stefan-Merettig
2016-02-29 14:29 ` [ruby-core:74055] " co000ri
2016-02-29 16:40 ` [ruby-core:74056] " funny.falcon
2016-02-29 20:40 ` [ruby-core:74064] " shevegen
2016-03-01  2:23 ` [ruby-core:74072] " nobu
2016-03-01  2:24 ` [ruby-core:74073] " nobu
2016-03-14  1:42 ` [ruby-core:74293] " Ruby-Lang
2016-03-14  1:44 ` [ruby-core:74294] " Ruby-Lang
2016-03-14 16:46 ` [ruby-core:74299] " mame
2016-03-15  1:35 ` [ruby-core:74317] " nobu
2016-03-15  3:41 ` [ruby-core:74323] " mame
2016-03-15 19:56 ` [ruby-core:74352] " Stefan-Merettig
2016-03-15 20:06 ` [ruby-core:74353] " funny.falcon
2016-03-16  8:57 ` [ruby-core:74368] " hanachin
2016-03-17  6:07 ` [ruby-core:74396] " shyouhei
2016-03-17  7:48 ` [ruby-core:74402] " nobu
2016-03-17 19:52 ` [ruby-core:74439] " rpc
2016-03-17 20:53 ` [ruby-core:74440] " rpc
2016-03-17 21:22   ` [ruby-core:74441] " Matthew Kerwin
2017-09-28 12:07 ` [ruby-core:83043] " vassilevsky
2017-09-28 13:23 ` [ruby-core:83044] " nobu
2017-09-28 13:32 ` [ruby-core:83045] " nobu

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