ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: artur.roszczyk@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:85443] [CommonRuby Feature#13581] Syntax sugar for method reference
Date: Tue, 06 Feb 2018 10:52:56 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-70226.20180206105255.1559440215b3290b@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-13581.20170519124435@ruby-lang.org

Issue #13581 has been updated by sevos (Artur Roszczyk).


phluid61 (Matthew Kerwin) wrote:
> sevos (Artur Roszczyk) wrote:
> > 
> > What are your thoughts?
> 
> I have two:
> 
> 1. As always: do we really need more magic symbols?  I like reading Ruby because it's *not* Perl.
I totally agree, but we still like -> {} syntax for lambdas, right? Let's play with ideas, maybe we can find something nice for a method selector, too ;)

> 
> 2. If you're adding new syntax, you don't have to be clever. Symbol has `:"#{x}"` so why not propose `y:::"#{x}"`? Not that it adds much over `y.method(x)`

You're totally right! I was looking at triple-colon as an operator taking two arguments. Your idea of looking at this as a double-colon lookup operator is actually great, look:

~~~ruby
irb(main):006:0> a :: :to_s
SyntaxError: (irb):6: syntax error, unexpected tSYMBEG, expecting '('
a :: :to_s
      ^
	from /Users/sevos/.rbenv/versions/2.4.0/bin/irb:11:in `<main>'
irb(main):007:0> Kernel :: :t
SyntaxError: (irb):7: syntax error, unexpected tSYMBEG, expecting tCONSTANT
A :: :t
      ^
	from /Users/sevos/.rbenv/versions/2.4.0/bin/irb:11:in `<main>'
~~~

We already have a lookup operator which takes object, constant on the left side and method name or constand on the right side.
Maybe it would be possible to support symbols on the right side and expand them to `method(:symbol)` call?
I would like just to emphasise again the need of respecting the method-to-be-called visibility depending on the current binding.


----------------------------------------
Feature #13581: Syntax sugar for method reference
https://bugs.ruby-lang.org/issues/13581#change-70226

* Author: americodls (Americo Duarte)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Some another programming languages (even Java, in version 8) has a cool way to refer a method as a reference.

I wrote some examples here: https://gist.github.com/americodls/20981b2864d166eee8d231904303f24b

I miss this thing in ruby.

I would thinking if is possible some like this:

~~~
roots = [1, 4, 9].map &Math.method(:sqrt)
~~~

Could be like this:

~~~
roots = [1, 4, 9].map Math->method
~~~

What do you guys thinking about it?



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

  parent reply	other threads:[~2018-02-06 10:53 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-13581.20170519124435@ruby-lang.org>
2017-05-19 12:44 ` [ruby-core:81282] [CommonRuby Feature#13581] Syntax sugar for method reference americodls
2017-05-19 13:37 ` [ruby-core:81283] " hanmac
2017-05-19 14:16 ` [ruby-core:81285] " americodls
2017-05-19 14:43 ` [ruby-core:81286] " hanmac
2017-05-20  0:27 ` [ruby-core:81296] " americodls
2017-08-31  6:31 ` [ruby-core:82556] " matz
2017-08-31  8:48 ` [ruby-core:82575] " nobu
2017-08-31 10:10 ` [ruby-core:82580] " hanmac
2017-08-31 12:10 ` [ruby-core:82582] " zverok.offline
2017-08-31 12:30 ` [ruby-core:82583] " takashikkbn
2017-08-31 12:56 ` [ruby-core:82584] " hanmac
2017-08-31 13:12 ` [ruby-core:82586] " takashikkbn
2017-08-31 14:27 ` [ruby-core:82588] " nobu
2017-08-31 14:31 ` [ruby-core:82589] " nobu
2017-08-31 14:51 ` [ruby-core:82590] " hanmac
2017-09-01  0:56 ` [ruby-core:82597] " muraken
2017-09-01  6:15 ` [ruby-core:82611] " zverok.offline
2017-09-01  6:36 ` [ruby-core:82612] " tom.dalling+ruby-lang
2017-09-01  8:30 ` [ruby-core:82614] " lord.thom
2017-10-19  1:46 ` [ruby-core:83365] " americodls
2018-01-24  9:49 ` [ruby-core:85038] " zverok.offline
2018-01-24 14:48 ` [ruby-core:85053] " danieldasilvaferreira
2018-01-25 12:23 ` [ruby-core:85114] " nobu
2018-01-25 12:31 ` [ruby-core:85115] " zverok.offline
2018-02-01 22:05 ` [ruby-core:85329] " mpapis
2018-02-01 23:13 ` [ruby-core:85330] " nobu
2018-02-02  1:51 ` [ruby-core:85332] " duerst
2018-02-02  5:33 ` [ruby-core:85334] " nobu
2018-02-02  8:20 ` [ruby-core:85340] " hanmac
2018-02-02  8:27 ` [ruby-core:85341] " nobu
2018-02-02  8:37 ` [ruby-core:85342] " hanmac
2018-02-02 10:57 ` [ruby-core:85345] " nobu
2018-02-04 20:10 ` [ruby-core:85380] " landon.grindheim
2018-02-04 21:12 ` [ruby-core:85381] " merch-redmine
2018-02-05 17:39 ` [ruby-core:85409] " artur.roszczyk
2018-02-06  6:14 ` [ruby-core:85439] " nobu
2018-02-06  8:19 ` [ruby-core:85440] " artur.roszczyk
2018-02-06  8:39 ` [ruby-core:85441] " matthew
2018-02-06 10:52 ` artur.roszczyk [this message]
2018-02-06 13:15 ` [ruby-core:85445] " matthew
2018-02-12 23:54 ` [ruby-core:85513] " cben
2018-02-14  0:52 ` [ruby-core:85533] " artur.roszczyk
2018-03-26 21:43 ` [ruby-core:86315] " pvande
2018-04-23  7:00 ` [ruby-core:86653] " keystonelemur
2018-05-17  6:45 ` [ruby-core:87102] " matz
2018-05-23  9:47 ` [ruby-core:87234] " cben
2018-11-10  5:01 ` [ruby-core:89764] " I.kerseymer
2018-11-12  7:20 ` [ruby-core:89773] " nobu
2018-11-12 10:29 ` [ruby-core:89774] " zverok.offline
2018-11-14 14:46 ` [ruby-core:89794] " shevegen
2018-11-15  1:50 ` [ruby-core:89800] " nobu
2018-11-15  8:42 ` [ruby-core:89804] " zverok.offline
2018-11-15 10:02 ` [ruby-core:89807] " alex.wayfer
2018-11-15 10:09 ` [ruby-core:89808] " zverok.offline
2018-11-15 10:26 ` [ruby-core:89810] " alex.wayfer
2018-11-15 10:58 ` [ruby-core:89811] " zverok.offline
2018-11-26 20:10 ` [ruby-core:90078] " shevegen
2018-12-09 22:19 ` [ruby-core:90385] " sean.m.huber
2018-12-10  2:25 ` [ruby-core:90388] " nobu
2018-12-10  4:12 ` [ruby-core:90391] " sean.m.huber
2018-12-11  8:28 ` [ruby-core:90416] " sean.m.huber
2018-12-13 16:58 ` [ruby-core:90520] " sean.m.huber
2018-12-13 17:51 ` [ruby-core:90521] " headius
2018-12-19 11:30 ` [ruby-core:90618] " zverok.offline

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-70226.20180206105255.1559440215b3290b@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).