https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112014-01-12T12:49:17ZRuby Issue Tracking SystemRuby master - Feature #9401: Yet another syntax for literal anonymous functions (lambdas)https://redmine.ruby-lang.org/issues/9401?journal_id=442282014-01-12T12:49:17Zalexeymuranov (Alexey Muranov)
<ul></ul><p>An anonymous "function" (not really a function) without arguments would be like this:</p>
<pre><code>timer = {\=> Time.now }
</code></pre>
<hr>
<p>Maybe there is no need to make it look so much like a hash, so the following looks to me like a good option either:</p>
<pre><code>f = {\ x -> x*x }
timer = {\-> Time.now }
</code></pre> Ruby master - Feature #9401: Yet another syntax for literal anonymous functions (lambdas)https://redmine.ruby-lang.org/issues/9401?journal_id=442332014-01-12T22:35:23Zalexeymuranov (Alexey Muranov)
<ul></ul><p>I have realized that the backslash may conflict with explicit line continuation. In that case, "almost any" symbol would work to distinguish a "lambda" from a hash. For example: <code>{^ x => x*x }</code>. (I've read that initially Church wrote <code>x̂</code> -- "x-hat", and not <code>λx</code>.)</p> Ruby master - Feature #9401: Yet another syntax for literal anonymous functions (lambdas)https://redmine.ruby-lang.org/issues/9401?journal_id=442352014-01-12T23:36:37Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>What about <code>(^x) {x*x}</code>?</p> Ruby master - Feature #9401: Yet another syntax for literal anonymous functions (lambdas)https://redmine.ruby-lang.org/issues/9401?journal_id=442592014-01-13T09:14:21Zalexeymuranov (Alexey Muranov)
<ul></ul><p>Nobuyoshi Nakada wrote:</p>
<blockquote>
<p>What about <code>(^x) {x*x}</code>?</p>
</blockquote>
<p>I think, my initial attempt was closer to lambda calculus notation <code>(λx(x*x))</code> or <code>(λx.x*x)</code>, to its modern variant <code>x ⟼ x*x</code>, to Haskell <code>\x -> x*x</code>, to Ruby block syntax <code>{|x| x*x }</code>, and to Ruby hash syntax <code>{ 2 => 2*2 }</code>.</p>
<p>Another option: make it openly similar to the block syntax: <code>{\|x| x*x }</code> or <code>{^|x| x*x }</code>. Other options:</p>
<ul>
<li>
<code>{<x> x*x }</code>, <code>{<> Time.now }</code>,</li>
<li>
<code>{<x>=> x*x }</code>,</li>
<li>
<code>{|x|=> x*x }</code>,</li>
<li>
<code>{|x|> x*x }</code> be a <em>proc</em> and <code>{|x|-> x*x }</code> be a <em>lambda</em>.</li>
</ul>
<p>Also, a double backslash would not conflict with a line break:</p>
<ul>
<li>
<code>{\\ x => x*x }</code>, <code>{\\=> Time.now }</code>.</li>
</ul>
<p>Sorry, i cannot choose myself the best syntax, i just do not like <code>->(x){ ... }</code> (strange placement of the "arrow", and it looks like a method call with a block, but the block parameters are mysteriously missing from the block and are found outside in parentheses, where arguments would be expected).</p>
<p><em>Edited 2014-04-03</em></p> Ruby master - Feature #9401: Yet another syntax for literal anonymous functions (lambdas)https://redmine.ruby-lang.org/issues/9401?journal_id=955782021-12-23T23:43:57Zhsbt (Hiroshi SHIBATA)hsbt@ruby-lang.org
<ul><li><strong>Project</strong> changed from <i>14</i> to <i>Ruby master</i></li></ul>