https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112013-05-03T09:17:07ZRuby Issue Tracking SystemRuby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=390942013-05-03T09:17:07Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>If it were introduced, how could you pass an array with a block?</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=390952013-05-03T09:17:35Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Category</strong> set to <i>syntax</i></li><li><strong>Status</strong> changed from <i>Open</i> to <i>Feedback</i></li></ul> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=390982013-05-03T16:25:04Zalexeymuranov (Alexey Muranov)
<ul></ul><p>=begin<br>
You are right, there is a problem. It is similar to the problem with hashes:</p>
<p>def f(h); end<br>
f {1=>2}</p>
<a name="gt-SyntaxError-unexpected-gt-expecting-"></a>
<h1 >=> SyntaxError: unexpected =>, expecting '}'<a href="#gt-SyntaxError-unexpected-gt-expecting-" class="wiki-anchor">¶</a></h1>
<p>It can be worked around in the same way:</p>
<p>foo([1, 2, 3]) [x] {x*x}</p>
<p>But there will be incompatibilities.<br>
I will think more about it.</p>
<p>P.S. The problem appears only if the array is the first argument, otherwise it would be clear because of the absence of comma.<br>
=end</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=390992013-05-03T16:32:09Zalexeymuranov (Alexey Muranov)
<ul></ul><p>=begin<br>
From the top of my mind, i can propose only this:</p>
<p>p = lambda [x]->{<br>
# ...<br>
}</p>
<p>[2, 3, 4].map [x]->{x*x}.reduce [0, 1] [m, o]->{m << o}</p>
<p>(i didn't like the new lambda syntax anyway:) ).</p>
<p>Another possibility:</p>
<p>p = lambda [x]:{<br>
# ...<br>
}</p>
<p>collection.each [element] : do<br>
# ...<br>
end</p>
<p>[2, 3, 4].map [x]:{x*x}.reduce([0, 1]) [m, o]:{m << o}</p>
<p>(This might conflict with the ternary expression.)</p>
<p>The current syntax for comparison:</p>
<p>[2, 3, 4].map {|x| x*x}.reduce([0, 1]) {|m, o| m << o}<br>
=end</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=391042013-05-03T18:40:47Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>=begin<br>
It's unacceptable to distinguish two semantics of "(({[ ]}))" by a token following ((<em>after</em>)) it.<br>
=end</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=391052013-05-03T20:17:45Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>I don't think the syntax cannot be defined without conflict.<br>
Prove me I am wrong.</p>
<p>Matz.</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=391102013-05-03T22:24:50Zalexeymuranov (Alexey Muranov)
<ul></ul><p>=begin<br>
I agree, it is getting complicated, maybe it was a bad idea. It may be closed if you do not think it is worth consideration.</p>
<p>The best i could think of was to allow to use some symbol, the colon for example, to separate explicitly the block from the list of argument:</p>
<p>p = lambda : [x] {<br>
# ...<br>
}</p>
<p>collection.each : [element] do<br>
# ...<br>
end</p>
<p>But it is getting complicated and not very readable.<br>
=end</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=391172013-05-04T15:12:03Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>It conflicts with ternary expressions, and symbol literals.</p>
<p>You should abandon use of colon and brackets.</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=391202013-05-04T18:14:25Zalexeymuranov (Alexey Muranov)
<ul></ul><p>=begin<br>
Nobu: i do not think the conflict with ternary expression is the worst part: i think that if in ambiguous cases the colon was interpreted as a part of ternary expression, there would be no conflict with existing code.</p>
<p>It was probably the choice of words (({each})) and (({do})) that bothered me. (({each})) sounds more like a name of a quantifier that should be followed by parameter names, than like a name of a method.</p>
<p>After all, in method definitions the list of parameters is not separated from the body either:</p>
<p>def foo(x) x*x end</p>
<p>proc do |x| x*x end<br>
=end</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=394632013-05-21T16:34:42Zalexeymuranov (Alexey Muranov)
<ul></ul><p>=begin<br>
I do not mind this being closed, i do not see how this can be made consistent with the existing syntax, and probably my reason for suggesting this was not valid, but as a side note, i want to mention that i have just discovered that in Combinatory Logic, when a lambda term from Lambda Calculus is converted to an equivalent combinatorial term, an alternative intermediate notation used sometimes for "(({λx.M}))" is "(({[x].M}))":<br>
((<a href="URL:http://plato.stanford.edu/entries/logic-combinatory/#2.3" class="external">URL:http://plato.stanford.edu/entries/logic-combinatory/#2.3</a>)).<br>
=end</p> Ruby master - Feature #8361: Alternative syntax for block parameterhttps://redmine.ruby-lang.org/issues/8361?journal_id=396322013-06-02T16:02:45Zzzak (zzak _)
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul><p>See <a href="/issues/8361">[ruby-core:55094]</a></p>