https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17097754782011-09-26T00:04:01ZRuby Issue Tracking SystemRuby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=209792011-09-26T00:04:01Zwaj (Juan Wajnerman)jwajnerman@manas.com.ar
<ul></ul><p>How about "object.:method" ? Looks more Ruby style for me.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=209812011-09-26T01:23:08Zaprescott (Adam Prescott)
<ul></ul><p>What about object:method ? The \ version doesn't seem very appealing.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=209842011-09-26T05:13:09Zdrbrain (Eric Hodel)drbrain@segment7.net
<ul><li><strong>Category</strong> set to <i>core</i></li></ul><p>=begin<br>
I find myself rarely needing to call #method and I don't often see code where other people call #method, so I don't see the need to add special syntax for it. Is there a reason why you use #method very often and that having a more compact syntax would help?</p>
<p>Note that \ can be used at the end of a line to continue it to the next line:</p>
<p>return <br>
really_long_expression<br>
=end</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=209872011-09-26T05:53:12ZAnonymous
<ul></ul><p>Of note, there is already a working patch (for a very similar feature) for the 1.9 branch at the ruby-patches github repo [0], ported from the old Suby experiment project [1].</p>
<p>It doesn't use ".", just "" and has an implicit self form, too. So:</p>
<p>\class #</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=209902011-09-26T07:23:08Zyeban (Anurag Priyam)anurag08priyam@gmail.com
<ul></ul><p>On Sun, Sep 25, 2011 at 8:34 PM, Juan Wajnerman <a href="mailto:jwajnerman@manas.com.ar" class="email">jwajnerman@manas.com.ar</a> wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-6 priority-4 priority-default closed" title="Feature: How about new syntax: "object.\method" returns a Method instance? (Rejected)" href="https://bugs.ruby-lang.org/issues/5364">#5364</a> has been updated by Juan Wajnerman.</p>
<p>How about "object.:method" ? Looks more Ruby style for me.</p>
</blockquote>
<p>Haskell uses '' to create lambda which seems very natural to me. I<br>
like the idea of using '' to get get method objects in Ruby.</p>
<p>--<br>
Anurag Priyam</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=209922011-09-26T09:29:07Zjballanc (Joshua Ballanco)jballanc@gmail.com
<ul></ul><p>On Sun, Sep 25, 2011 at 10:36 AM, Joey Zhou <a href="mailto:yimutang@gmail.com" class="email">yimutang@gmail.com</a> wrote:</p>
<blockquote>
<ol>
<li>It makes people happy, writing less code, and no harm to readability.</li>
</ol>
</blockquote>
<p>Personally, I would like to hear more on how having another operator for new<br>
Rubyists to learn does not harm readability? One of the oft-cited advantages<br>
of Ruby vs Perl is that Perl so often devolves into characters<br>
indistinguishable from line-noise. Admittedly, it does seem that certain<br>
languages are more than happy to chase down this rabbit hole (Haskell,<br>
Scala, C++, etc.), but I think Ruby is not competing for mind-share with<br>
these sorts of languages. Rather, I think Ruby could stand to learn a lot<br>
from the simplicity of a language like Lua.</p>
<p>Furthermore, I do not think that the worst part of the<br>
obj.method(:meth_name) form is its verbosity or really any part of its<br>
syntax. Instead, what troubles me is all of the various hidden differences<br>
between a method object, a proc object, and a proc(lambda) object, and the<br>
relative uselessness of detached methods (e.g. they can only be rebound to<br>
objects of the same class; not even subclasses are valid). I would rather<br>
see these addressed before worrying about adding new syntax.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=209952011-09-26T10:53:07Znormalperson (Eric Wong)normalperson@yhbt.net
<ul></ul><p>Joshua Ballanco <a href="mailto:jballanc@gmail.com" class="email">jballanc@gmail.com</a> wrote:</p>
<blockquote>
<p>On Sun, Sep 25, 2011 at 10:36 AM, Joey Zhou <a href="mailto:yimutang@gmail.com" class="email">yimutang@gmail.com</a> wrote:</p>
<blockquote>
<ol>
<li>It makes people happy, writing less code, and no harm to readability.</li>
</ol>
</blockquote>
<p>Personally, I would like to hear more on how having another operator for new<br>
Rubyists to learn does not harm readability? One of the oft-cited advantages<br>
of Ruby vs Perl is that Perl so often devolves into characters<br>
indistinguishable from line-noise.</p>
</blockquote>
<p>Completely agreed. A smaller syntax and fewer operators improves<br>
readability and learnability in my experience[1]. I think<br>
pronounce-ability is a good factor to readability, too.</p>
<p>Code is written once and read many times (often by people who are not<br>
the author), so optimize for readability.</p>
<p>[1] - I've done a fair bit of Perl, but also languages with small<br>
syntaxes like AWK and C.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=209962011-09-26T11:19:36Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul><p>We need a needs fot this syntax. I don't reject it right now, because there's a<br>
room for someone to find a real use case for it. Through personally I'm skeptical<br>
about existance of such thing.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=210002011-09-26T12:16:28Ztrans (Thomas Sawyer)
<ul></ul><p>It's just a convenience thing, so I think it's not possible to prove a "real use case" as such. And as only a static syntax it's probably not a convenience worth the bother. However it might be more understandable if it could also be used dynamically, e.g.</p>
<p>m = :split<br>
str:m</p>
<p>Syntax not withstanding. I suppose if this were to be done, the nicest syntax would be:</p>
<p>str#split</p>
<p>and</p>
<p>str#:m</p>
<p>In which case comments would require a space before the hash mark.</p>
<p>But, I think this hints at a larger matter that a future version of Ruby could really use -- real meta-programming functions. As things stand Ruby's meta-programming methods are fragile. Hence the need for things like <strong>id</strong> and <strong>send</strong>. Likewise, if #method is overwrite by some class, it could spell a bad day for some meta-code. As to the syntax for real meta-programming functions, I'm not sure. Perhaps a "global meta-izing syntax" like:</p>
<p>$(object).id<br>
$(object).send(...)</p>
<p>And then perhaps #[] could get a method:</p>
<p>$(object)[:foo]</p>
<p>On the other hand, perhaps $ could be used as a "meta-message" device:</p>
<p>object$id<br>
object$send(...)<br>
object$:foo</p>
<p>In any case, one way or the other a more robust address of meta-programming would be a good thing.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=210012011-09-26T12:38:20Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Open</i></li></ul><p>Hello,</p>
<p>To prevent `bikeshed' discussion, we should focus use case first<br>
about this ticket, I think. Why don't you talk about the concrete<br>
notation after that?</p>
<p>I come up with some use cases. First case:</p>
<p>ary.map {|x| x+3 }<br>
ary.map(&3.+)</p>
<p>I like the latter not only because it is shorter, but also because<br>
I don't have to bother about the name of the temporal variable.<br>
We can already write ary.map(&:succ) in 1.9, so I think this style<br>
will become more in demand.<br>
Indeed, there is a trade-off between readability and writability.<br>
I think it is a matter of getting familiar with it, though.</p>
<p>Another one for DSL. Consider rspec example:</p>
<p>lambda { foo.bar(baz) }.should raise(SomeError)<br>
foo.\bar.with(baz).should raise(SomeError)</p>
<p>I think the latter is more readable than the formar.<br>
I guess there are many possible use case in this field.</p>
<p>Finally, use case in future.<br>
Ruby's Method class is poor currently.<br>
I believe this proposal will encourage us to enrith Method class.<br>
For example, I often use Object#method to glance over an unfamiliar<br>
library:</p>
<p>irb(main):001:0> unfamiliar_obj.methods - 0.methods<br>
[..., interesting_method, ...]</p>
<p>After I find an interesting method, I also want to read the rdoc<br>
in similar way:</p>
<p>irb(main):002:0> unfamiliar_obj.\interesting_method.doc</p>
<p>Of course there is no Method#doc currently. I think this shorthand<br>
notation will enrich such a feature.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=210052011-09-26T15:37:42Zyimutang (Joey Zhou)
<ul></ul><p>Well, Proc instances and Method instances are both closures. To obtain a closure, the Ruby idiom is almost from a block, not very often from a method. But in some situation, creating a closure from a method is more natural.</p>
<p>For example, if I want this:</p>
<pre><code>['file1', 'file2', 'file3'].map {|f| open(f) }
</code></pre>
<p>how about:</p>
<pre><code>['file1', 'file2', 'file3'].map &\open
</code></pre>
<p>and:<br>
str = "abcdabcdabcd"<br>
%w(a b c d).map {|sep| str.split(sep)}</p>
<p>how about:</p>
<pre><code>%w(a b c d).map &str.\split
</code></pre>
<p>Of course, every Method instance can be converted to a Proc object with Method#to_proc.</p>
<pre><code>str.method(:split)
</code></pre>
<p>is somewhat like:</p>
<pre><code>lambda {|*args| str.send(:split, *args) }
</code></pre>
<p>but I'm afraid it's verbose to write and read.</p>
<p>I've just begun to learn Python recently, and find some interesting differences between the two languages.</p>
<p>Python's lambda is trivial, only one line code is allowed to create a lambda. However, its functions are first class objects, so that can be assigned to another variable easily.</p>
<p>Python seems mainly using objects from function to do some functional programming thing, while Ruby seems mainly using objects from blocks.</p>
<pre><code>>>> a = lambda n: n + 1
>>> a
<function <lambda> at 0x011F6170>
>>> def foo(n):
return n + 1
>>> b = foo
>>> b
<function foo at 0x011F2670>
</code></pre>
<p>whether from a lambda, or from a function, the returnning objects are both functions.</p>
<p>But in Ruby, if we do the similar thing, a will be a Proc instance, and b will be a Method instance.</p>
<p>Ruby distinguishes Proc and Method, but seems not paying much attention to Method? You can obtain a closure from a method, but it seems not Ruby idiom?</p>
<p>Joshua Ballanco and Yusuke Endoh san remind me the deeper subject: what's the future plan about the relationship between Proc and Method?</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=210172011-09-27T03:59:07Zjballanc (Joshua Ballanco)jballanc@gmail.com
<ul></ul><p>On Monday, September 26, 2011 at 2:37 AM, Joey Zhou wrote:</p>
<blockquote>
<p>Joshua Ballanco and Yusuke Endoh san remind me the deeper subject: what's the future plan about the relationship between Proc and Method?</p>
</blockquote>
<p>I think that, in order to address Method and Proc and how to go forward with them, we first need to meditate a bit about Ruby's treatment of first-class environments (or, in Ruby parlance, 'binding'). I will be giving a presentation at RubyConf this coming Thursday in which I hope to present what I feel are the biggest concerns surrounding environments. If anyone will be attending and would like to discuss bindings, methods, procs, and lambdas, I would love to get together and chat...</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=210182011-09-27T06:36:30Zkstephens (Kurt Stephens)
<ul></ul><p>Do we <em>really</em> need new syntax to support a basic metaprogramming feature?<br>
If Ruby metaprogramming is first-class, no additional syntax should be needed. This is a slippery slope.<br>
This is what makes Ruby beautiful. :)</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=211012011-10-02T23:00:53Zyimutang (Joey Zhou)
<ul></ul><p>How about this?</p>
<p>I want to create an enumerator from a method, the normal way is using the Object#to_enum method, if we add a method Method#to_enum, we can write in a clearer way. For example:</p>
<p>str.each_char # want an enumerator from this</p>
<a name="normal-way-gt-strto_enumeach_char"></a>
<h1 >normal way ==> str.to_enum(:each_char)<a href="#normal-way-gt-strto_enumeach_char" class="wiki-anchor">¶</a></h1>
<a name="clearer-way-gt-streach_charto_enum"></a>
<h1 >clearer way ==> str.\each_char.to_enum<a href="#clearer-way-gt-streach_charto_enum" class="wiki-anchor">¶</a></h1>
<p>of course, str.each_char returns an enumerator itself, but some other methods are not.</p>
<p>Dir.glob("*.rb") {|f| } # if I want an enumerator, not an array:</p>
<a name="normal-way-gt-Dirto_enumglob-rb"></a>
<h1 >normal way ==> Dir.to_enum(:glob, "*.rb")<a href="#normal-way-gt-Dirto_enumglob-rb" class="wiki-anchor">¶</a></h1>
<a name="clearer-way-gt-Dirglobto_enumrb"></a>
<h1 >clearer way ==> Dir.\glob.to_enum("*.rb")<a href="#clearer-way-gt-Dirglobto_enumrb" class="wiki-anchor">¶</a></h1>
<p>str.scan(/[abc]+/) {|s| }</p>
<a name="normal-way-gt-strto_enumscan-abc"></a>
<h1 >normal way ==> str.to_enum(:scan, /[abc]+/)<a href="#normal-way-gt-strto_enumscan-abc" class="wiki-anchor">¶</a></h1>
<a name="clearer-way-gt-strscanto_enumabc"></a>
<h1 >clearer way ==> str.\scan.to_enum(/[abc]+/)<a href="#clearer-way-gt-strscanto_enumabc" class="wiki-anchor">¶</a></h1>
<p>array.sort {|a,b| }</p>
<a name="normal-way-gt-arrayto_enumsort"></a>
<h1 >normal way ==> array.to_enum(:sort)<a href="#normal-way-gt-arrayto_enumsort" class="wiki-anchor">¶</a></h1>
<a name="clearer-way-gt-arraysortto_enum"></a>
<h1 >clearer way ==> array.\sort.to_enum<a href="#clearer-way-gt-arraysortto_enum" class="wiki-anchor">¶</a></h1>
<p>In my opinion, compare with the methods which take a method name as its argument, "object.\method" style is more readable.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=215172011-10-25T09:34:12Ztrans (Thomas Sawyer)
<ul></ul><p>I wonder if</p>
<p>str->:each_char</p>
<p>Would be viable.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=215662011-10-26T14:53:28Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Hi,</p>
<p>(11/10/25 9:34), Thomas Sawyer wrote:</p>
<blockquote>
<p>I wonder if</p>
<p>str->:each_char</p>
<p>Would be viable.</p>
</blockquote>
<p>No.</p>
<ol>
<li>
<p>it doesn't appear what it means well.</p>
</li>
<li>
<p>it caused hundreds of conflicts.</p>
</li>
</ol>
<p>--<br>
Nobu Nakada</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=252172012-03-27T03:22:27Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>Anyone is interested in facilitating the discussion?</p>
<p>Personally, I believe this proposal is the right way.<br>
I tentatively assign this to matz, but I don't think<br>
this is going to end well.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=252272012-03-27T04:17:28Ztrans (Thomas Sawyer)
<ul></ul><p>Personally I think it's a ugly notation. Also methods aren't 1st class --you don't get the same method object each time. If we did, then I say it agree it would be important to have a concise syntax.</p> Ruby master - Feature #5364: How about new syntax: "object.\method" returns a Method instance?https://bugs.ruby-lang.org/issues/5364?journal_id=254722012-03-31T00:32:08Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Rejected</i></li></ul><p>I am not against adding syntax notation to get method object, but I am not satisfied with all proposed notations. I feel they are not intuitive enough. Maybe we can accustom to one of them in the future. Until that I can stand with #method().</p>
<p>Matz.</p>