https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112011-01-19T03:45:12ZRuby Issue Tracking SystemRuby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=153192011-01-19T03:45:12Znaruse (Yui NARUSE)naruse@airemix.jp
<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>=begin</p>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=153452011-01-19T23:13:17Zaustin (Austin Ziegler)halostatue@gmail.com
<ul></ul><p>=begin<br>
On Tue, Jan 18, 2011 at 12:51 AM, Charles Nutter <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> wrote:</p>
<blockquote>
<p>This is one Groovy feature I tend to like.</p>
</blockquote>
<p>[…]</p>
<blockquote>
<p>This syntax would make it easier to integrate with other languages that have different<br>
naming rules. For example, =!@+= is a valid operator in Scala. With this syntax, you<br>
could invoke it as</p>
<p>foo."=!@+=" bar</p>
</blockquote>
<p>How does one define this sort of named method, or is it something that<br>
we declare must be handled in method_missing (or an equivalent for<br>
JRuby/Scala, for example) if it's not an otherwise legal Ruby method<br>
name?</p>
<a name="-austin"></a>
<h2 >-austin<a href="#-austin" class="wiki-anchor">¶</a></h2>
<p>Austin Ziegler • <a href="mailto:halostatue@gmail.com" class="email">halostatue@gmail.com</a> • <a href="mailto:austin@halostatue.ca" class="email">austin@halostatue.ca</a><br>
<a href="http://www.halostatue.ca/" class="external">http://www.halostatue.ca/</a> • <a href="http://twitter.com/halostatue" class="external">http://twitter.com/halostatue</a></p>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=153462011-01-19T23:53:46Znow (Nikolai Weibull)now@disu.se
<ul></ul><p>=begin<br>
On Wed, Jan 19, 2011 at 14:56, Austin Ziegler <a href="mailto:halostatue@gmail.com" class="email">halostatue@gmail.com</a> wrote:</p>
<blockquote>
<p>On Tue, Jan 18, 2011 at 12:51 AM, Charles Nutter <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> wrote:</p>
</blockquote>
<blockquote>
<blockquote>
<p>This syntax would make it easier to integrate with other languages that have different<br>
naming rules. For example, =!@+= is a valid operator in Scala. With this syntax, you<br>
could invoke it as</p>
<p>foo."=!@+=" bar</p>
</blockquote>
</blockquote>
<blockquote>
<p>How does one define this sort of named method, or is it something that<br>
we declare must be handled in method_missing (or an equivalent for<br>
JRuby/Scala, for example) if it's not an otherwise legal Ruby method<br>
name?</p>
</blockquote>
<p>Class.new {<br>
define_method :'=!@+=' do<br>
puts 'I have no idea what this method is supposed to do, though'<br>
end<br>
}.new.send :'=!@+='</p>
<p>And, as demonstrated, isn’t #send good enough?</p>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=153512011-01-20T06:23:13Znow (Nikolai Weibull)now@disu.se
<ul></ul><p>=begin<br>
On Wed, Jan 19, 2011 at 21:58, Gary Wright <a href="mailto:gwtmp01@mac.com" class="email">gwtmp01@mac.com</a> wrote:</p>
<blockquote>
<p>On Jan 18, 2011, at 12:51 AM, Charles Nutter wrote:</p>
<blockquote>
<p>For non-standard or arbitrary method names, it would be nice to have a way to invoke them directly that doesn't require the parser to be made more complex nor require an intermediate "send" call. Groovy does this by allowing the following form:</p>
<p>foo."asdf"()</p>
</blockquote>
</blockquote>
<blockquote>
<p> foo.{some_variable}()</p>
</blockquote>
<blockquote>
<p>I've always found the use of Kernel#send for dynamic method dispatch to be a bit awkward and would prefer something that was syntactically similar to static method dispatch rather than the current dependency on the 'magic' behavior of Kernel#send.</p>
</blockquote>
<p>Could you explain how foo.{some_variable}() is less magic than<br>
foo.send(some_variable)? I am currently of the opposite opinion.</p>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=153562011-01-20T08:13:10Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>=begin<br>
On Wed, Jan 19, 2011 at 2:58 PM, Gary Wright <a href="mailto:gwtmp01@mac.com" class="email">gwtmp01@mac.com</a> wrote:</p>
<blockquote>
<p>Maybe I'm crazy, but could I suggest something a little more general?</p>
<p> foo.{expression}(arg1)</p>
<p>to have the same semantics as</p>
<p> foo.send(expression, arg1)</p>
</blockquote>
<p>I don't want something that just resolves to doing "send" under the<br>
covers. I want this code:</p>
<p>foo."something"()</p>
<p>to parse identically to:</p>
<p>foo.something()</p>
<p>What I want is purely a syntax-level quoting mechanism for method invocation.</p>
<blockquote>
<p>I've always found the use of Kernel#send for dynamic method dispatch to be a bit awkward and would prefer something that was syntactically similar to static method dispatch rather than the current dependency on the 'magic' behavior of Kernel#send.</p>
</blockquote>
<p>I agree, but "send" also changes things in subtle ways. I just want a<br>
way to specify a syntactically "unfriendly" method call and have it<br>
actually resolve to a plain old CALL, FCALL, or VCALL (in MRI AST<br>
parlance).</p>
<p>FWIW, there have been proposals to add this sort of "symbolic freedom"<br>
to Java method invocations using a similar form:</p>
<p>foo.#"something"</p>
<ul>
<li>Charlie</li>
</ul>
<blockquote>
<p>Perhaps a syntactic approach to dynamic dispatch would enable more interesting optimizations since it would be clear that something 'interesting' was going on rather than just a generic method call to a magic method like Kernel#send.</p>
</blockquote>
<p>If you mean that the above syntax would actually parse to those<br>
literal call names (rather than bouncing through send) then I have no<br>
objections. I feel like foo."something" is cleaner, though, and the {}<br>
immediately says "block" to me. If that was your intent...I think<br>
that's going a bit too far :)</p>
<ul>
<li>Charlie</li>
</ul>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=153572011-01-20T08:13:30Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>=begin<br>
On Wed, Jan 19, 2011 at 8:53 AM, Nikolai Weibull <a href="mailto:now@bitwi.se" class="email">now@bitwi.se</a> wrote:</p>
<blockquote>
<p>And, as demonstrated, isn’t #send good enough?</p>
</blockquote>
<ul>
<li>It's longer :)</li>
<li>It defeats optimization, since you have to bounce through a "send"<br>
call to get to the eventual call. In essence, send typically forces a<br>
slow-path dynamic dispatch all the time. foo."something" would be a<br>
literal dispatch to the target method.</li>
<li>The default form of send routes around visibility. That's not always<br>
what you want.</li>
<li>On 1.8, send deepens the exception backtrace.</li>
</ul>
<p>The syntax proposed is basically a quoting mechanism for literal<br>
method calls. It doesn't replace send, it just expands what you can do<br>
with direct call syntax. send changes the dispatch logic in subtle<br>
ways.</p>
<ul>
<li>Charlie</li>
</ul>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=153922011-01-21T06:39:16Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>=begin<br>
On Wed, Jan 19, 2011 at 6:03 PM, Gary Wright <a href="mailto:gwtmp01@mac.com" class="email">gwtmp01@mac.com</a> wrote:</p>
<blockquote>
<p>I probably wasn't clear. I also don't want syntactic sugar for #send<br>
but instead a way to dynamically name a method without the extra step<br>
of looking up the implementation of #send.</p>
</blockquote>
<p>Ok, cool.</p>
<blockquote>
<p>I was trying to expand on your idea a bit to produce a more<br>
general approach that still addressed your use case:</p>
<p> foo.{"something"}()</p>
<p>can still be optimized to the same parse tree as</p>
<p> foo.something()</p>
<p>but it also admits the use of an arbitrary expression to generate<br>
the name of the method to call.</p>
</blockquote>
<p>It does, but my concern with it is that (in the same way as<br>
string-interpolated ."" syntax) it can't be made 100% parse-time. So I<br>
think the questions to be answered are (in this order):</p>
<ol>
<li>Do we feel it's useful to have a quoting mechanism for method<br>
invocation (that does not use send)?</li>
<li>Do we want that mechanism to allow runtime determination of the<br>
method to be called (and how does this water down the value of a<br>
pure-syntactical quoting mechanism)?</li>
<li>Do we want the runtime determination to allow arbitrary code</li>
</ol>
<p>Given that an interpolated mechanism could basically introduce any<br>
code, your syntax and string-interpolated syntax are largely the same<br>
feature (i.e. they both go all the way to (3) above.</p>
<p>I definitely want (1). I'm far more dubious on the value of (2) and<br>
(3) weighed against the benefit...</p>
<blockquote>
<p>BTW, I suspect that any of these ideas (single quotes, double quotes, or braces) is going to complicate the parser...</p>
</blockquote>
<p>Perhaps not as much as you might expect; a " is not a valid token<br>
after a ".", so there's no ambiguity.</p>
<ul>
<li>Charlie</li>
</ul>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=154042011-01-21T17:50:29Zsdsykes (Stephen Sykes)sdsykes@gmail.com
<ul></ul><p>=begin</p>
<blockquote>
<p>It does, but my concern with it is that (in the same way as<br>
string-interpolated ."" syntax) it can't be made 100% parse-time. So I<br>
think the questions to be answered are (in this order):</p>
<ol>
<li>Do we feel it's useful to have a quoting mechanism for method<br>
invocation (that does not use send)?</li>
<li>Do we want that mechanism to allow runtime determination of the<br>
method to be called (and how does this water down the value of a<br>
pure-syntactical quoting mechanism)?</li>
<li>Do we want the runtime determination to allow arbitrary code</li>
</ol>
<p>Given that an interpolated mechanism could basically introduce any<br>
code, your syntax and string-interpolated syntax are largely the same<br>
feature (i.e. they both go all the way to (3) above.</p>
<p>I definitely want (1). I'm far more dubious on the value of (2) and<br>
(3) weighed against the benefit...</p>
</blockquote>
<p>Yes, agree, if you want interpolation you can use send.</p>
<p>But using double quotes leads to an expectation of interpolation does it not?<br>
So would not single quotes be a better proposal in that case?</p>
<p>-Stephen</p>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=154072011-01-21T18:38:10Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>=begin<br>
On Fri, Jan 21, 2011 at 2:50 AM, Stephen Sykes <a href="mailto:sdsykes@gmail.com" class="email">sdsykes@gmail.com</a> wrote:</p>
<blockquote>
<p>Yes, agree, if you want interpolation you can use send.</p>
<p>But using double quotes leads to an expectation of interpolation does it not?<br>
So would not single quotes be a better proposal in that case?</p>
</blockquote>
<p>Yes, you are correct :)</p>
<p>foo.'something'()</p>
<ul>
<li>Charlie</li>
</ul>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=154172011-01-21T21:05:22Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>=begin<br>
Em 21-01-2011 07:37, Charles Oliver Nutter escreveu:</p>
<blockquote>
<p>On Fri, Jan 21, 2011 at 2:50 AM, Stephen Sykes<a href="mailto:sdsykes@gmail.com" class="email">sdsykes@gmail.com</a> wrote:</p>
<blockquote>
<p>Yes, agree, if you want interpolation you can use send.</p>
<p>But using double quotes leads to an expectation of interpolation does it not?<br>
So would not single quotes be a better proposal in that case?<br>
Yes, you are correct :)</p>
</blockquote>
<p>foo.'something'()</p>
</blockquote>
<p>Actually, I think this is easy discoverable by the interpreter. For<br>
instance, the interpreter can convert foo.'something' or foo."something"<br>
or foo."#{'some'}thing" to foo.something, but foo."#{something}" would<br>
be converted to "foo.send :something".</p>
<p>So, I would vote for the interpolation to be allowed... Additionally, I<br>
think that differently from "send", foo."#{something}" should not be<br>
allowed if "something" is a private method.</p>
<p>Rodrigo.</p>
<p>=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=161462011-03-21T20:06:15Zwardrop (Tom Wardrop)tom@tomwardrop.com
<ul></ul><p>=begin<br>
I agree, you'd want to support double-quotes and string interpolation, otherwise the introduction of the new syntax loses half its benefit. I don't see how interpolation could increase parser complexity, given that you could use the exact same string interpolation logic that already exists, and just map the result to as method invocation. The proposed syntax should be a direct replacement/alternative to #send, like how string interpolation, e.g. "The time is #{Time.now}" is an alternative to "The time is " + Time.now.to_s.<br>
=end</p> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=326932012-11-09T18:03:07Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/32693/diff?detail_id=23109">diff</a>)</li><li><strong>Target version</strong> set to <i>3.0</i></li></ul> Ruby master - Feature #4288: Allow invoking arbitrary method names with foo."something" syntaxhttps://bugs.ruby-lang.org/issues/4288?journal_id=683082017-12-12T08:40:00Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li></ul><p>I thought I have closed this issue long ago. Use <code>send</code>.</p>
<p>Matz.</p>