https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112013-03-27T03:31:12ZRuby Issue Tracking SystemRuby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=379422013-03-27T03:31:12Zgarysweaver (Gary Weaver)garysweaver@gmail.com
<ul></ul><p>Probably should have called it "expression lambda", not "statement lambda". Similarly "expression" not "value". Sorry, can't seem to edit.</p> Ruby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=379432013-03-27T03:34:46Zgarysweaver (Gary Weaver)garysweaver@gmail.com
<ul></ul><p>So, redefining the proposal somewhat, '-> an_expression' or '->> an_expression' would be a shortcut for '-> {an_expression}'.</p> Ruby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=379452013-03-27T05:43:50Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li><li><strong>Assignee</strong> set to <i>matz (Yukihiro Matsumoto)</i></li></ul><p>=begin<br>
What if the lambda takes the parameter e.g. (({->(x){x*x}}))?</p>
<p>Matz.<br>
=end</p> Ruby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=382002013-04-04T12:37:14Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Tracker</strong> changed from <i>Bug</i> to <i>Feature</i></li></ul> Ruby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=384662013-04-12T03:47:44Zgarysweaver (Gary Weaver)garysweaver@gmail.com
<ul></ul><p><a class="user active user-mention" href="https://redmine.ruby-lang.org/users/13">@matz (Yukihiro Matsumoto)</a>, You know best. :) !! I know that this request varies a bit when you consider that stab is a function call, but the goal is to de-uglify code that we are starting to have like:</p>
<p>some_method :some, :args, :here, -> {the block makes a single expression look ugly}</p>
<p>some_method :some, :args, :here, ->(x,y) {the block makes a single expression look ugly}</p>
<p>instead of the more beautiful expression lambda proposed as ->>. But, I think you are alluding to the issue that:</p>
<p>some_method :some, :args, :here, ->>(x,y) some expression</p>
<p>is bad, because with those parentheses, it looks like a function call to ->> which should take a block.</p>
<p>So, how about some other operator that could turn a single expression into a block?</p>
<p>Perhaps this could be ultracool, and look like:</p>
<p>some_class_method :some, :arg, ->(x,y)> some expression</p>
<p>The obvious problem with that is that, though, may be that ">" would be taking on a special meaning in certain contexts, which would be difficult to read (and even more context sensitive to interpret?).</p>
<p>So, I guess that the best solution is possibly a syntactical symbol that indicates that the expression that follows it should be converted into a block during parsing.</p>
<p>I'm probably way off though. I wish that ->> would work, but perhaps it should be ->| or something. Thanks for taking time to consider this. It is just a nice to have, but Ruby is a beautiful language, and lambdas get so ugly, even with stabs.</p> Ruby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=384682013-04-12T04:11:28Zgarysweaver (Gary Weaver)garysweaver@gmail.com
<ul></ul><p>Thinking about it a bit more, I guess it would have to be context sensitive. Just some character that is parsed when the block is being parsed that indicates that the following statement is a block. So maybe the best that could be done without a lot of overhead is whitespace between it, the method, and the block.</p>
<p>Then you just need to pick a good operator. I don't like the smiley here, but the world needs more smiles, so here it is for an example:</p>
<p>some_method :some, :args, :here, -> :) expression</p>
<p>Then you could also do:</p>
<p>def hello :) puts "hello world"</p>
<p>A single character that doesn't have many pixels like a colon would be best/most readable:</p>
<p>def hello : puts "hello world"</p>
<p>but colon is used by itself already in the ternary/conditional operator ?: (i.e., a ? b : c) so that might be confusing. Equals might look too much like an assignment:</p>
<p>def hello = puts "hello world"</p>
<p>I wish colon would work, because it would be a lot nicer-looking.</p>
<p>def a: b; def b: c; def c: d;</p>
<p>That just looks nice! :)</p> Ruby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=384692013-04-12T04:11:58Zgarysweaver (Gary Weaver)garysweaver@gmail.com
<ul></ul><p>Oops except then they are symbols. Darn, too much to worry about...</p> Ruby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=384732013-04-12T04:53:04Zheadius (Charles Nutter)headius@headius.com
<ul></ul><p>As a feature that affects all Ruby implementations, this should probably move to CommonRuby: <a href="https://bugs.ruby-lang.org/projects/common-ruby" class="external">https://bugs.ruby-lang.org/projects/common-ruby</a></p> Ruby master - Feature #8168: Feature request: support for (single) statement lambda syntax/definitionhttps://redmine.ruby-lang.org/issues/8168?journal_id=442172014-01-11T11:36:22Zalexeymuranov (Alexey Muranov)
<ul></ul><p>I do not understand the argument about the code presumably looking ugly with curly braces (maybe if code looks ugly, it is better to read poetry? :)).</p>
<p>I do not think that</p>
<pre><code>foo ->> Time.now
</code></pre>
<p>is more beautiful or clear than</p>
<pre><code>foo lambda{ Time.now }
</code></pre>
<hr>
<p>P.S. I think this proposal is somewhat related to <a class="issue tracker-2 status-7 priority-4 priority-default closed" title="Feature: New one-argument block syntax: &. (Feedback)" href="https://redmine.ruby-lang.org/issues/9076">#9076</a>.</p>
<p>P.P.S. I also think that the notation <code>->(x){ bar(x) ... }</code> was misplaced in the first place (should be more like something like <code>{ x |-> bar(x) ... }</code>, if usual mathematical notation is implied), and the proposed use of <code>->></code> looks to me even more inappropriate, unless it is not expected to have anything to do with mathematical notation.</p>
<p><em>Edited.</em></p>