https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112012-05-17T00:30:53ZRuby Issue Tracking SystemRuby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=266612012-05-17T00:30:53Zmame (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>FYI: There is similar (but not same) proposal: <a href="/issues/5474">[ruby-core:41772]</a></p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=276232012-07-01T06:27:47Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>File</strong> <a href="/attachments/2846">destructuring.pdf</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/2846/destructuring.pdf">destructuring.pdf</a> added</li><li><strong>Category</strong> set to <i>core</i></li><li><strong>Target version</strong> set to <i>2.0.0</i></li></ul><p>Attaching a one-minute slide. It doesn't cover the "construction" part of this request though.</p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=276612012-07-01T22:21:43Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>-1. I'd still like to see Ruby supporting CoffeeScript hash style for this common pattern:</p>
<p>Instead of<br>
a = 1; b = 2; c = {a: a, b: b}</p>
<p>I'd prefer to write just c = {a, b}. The current proposed syntax wouldn't allow such a feature in the future.... :(</p>
<p>By the way, I can't remember what is the current situation of an old proposition to allow things like {"#{interpolation}": value} as well as {'some string': value}.</p>
<p>Was it already accepted? Is there already a slide for it?</p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=276892012-07-02T03:22:15Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>Marc-Andre, your slide is received. Thank you!</p>
<p>Rodrigo, I don't know CoffeeScript, but what is the difference between OP's (second) proposal and yours?</p>
<blockquote>
<p>name = "John"<br>
last = "Smith"<br>
find({name, last}) # equals to => find({name: "John", last: "Smith"})</p>
</blockquote>
<blockquote>
<p>Instead of<br>
a = 1; b = 2; c = {a: a, b: b}<br>
I'd prefer to write just c = {a, b}.</p>
</blockquote>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=277592012-07-03T23:01:16Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>sorry but I couldn't find the proposal you're talking about, but looking at the examples it seems there is no difference.</p>
<p>But one thing that is supported in CoffeeScript and is not in the examples is to mix both forms. For example, in Ruby, that would mean:</p>
<p>b = 2; d = 4<br>
{a: 1, b, 'c' => 3, d } == { :a => 1, :b => b, 'c' => 3, :d => d }</p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=283352012-07-24T00:10:22Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>Edward Tsech and Marc-Andre Lafortune,</p>
<p>We discussed your slide at the developer meeting (7/21).</p>
<p>We were not sure if we can actually implement this feature in terms<br>
of yacc. Could you create an experimental patch?</p>
<p>Matz was basically positive to the feature itself, but wanted to<br>
focus on surely implementable syntax (with no parser conflict and<br>
with reasonable code).</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=283452012-07-24T01:20:44Ztrans (Thomas Sawyer)
<ul></ul><p>So this is a shortcut for?</p>
<p>name, last = john.values_at(:name, :last)</p>
<p>If so, long ago it was suggested Hash#[] support multiple keys:</p>
<p>name, last = john[[:name, :last]]</p>
<p>Not as short as <code>{name, last} = john</code>, but not quite as esoteric either.</p>
<p>If assigning from an array can work, eg.</p>
<p>john = ['John', 'Smith']<br>
name, last = john</p>
<p>Why not hash? So, just</p>
<p>john = {:name=>'John', :last=>'Smith'}<br>
name, last = john</p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=283512012-07-24T07:23:11Zcjheath (Clifford Heath)clifford.heath@gmail.com
<ul></ul><p>On 24/07/2012, at 2:20 AM, trans (Thomas Sawyer) wrote:</p>
<blockquote>
<p>If so, long ago it was suggested Hash#[] support multiple keys:</p>
<p>name, last = john[[:name, :last]]</p>
</blockquote>
<p>I'm very glad this didn't happen. I often have reason to use arrays as hash keys,<br>
and this would make that impossible.</p>
<p>Clifford Heath.</p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=283622012-07-24T09:28:21Ztrans (Thomas Sawyer)
<ul></ul><p>I made a mistake with that example.</p>
<p>name, last = john[:name, :last]</p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=283762012-07-24T11:53:56Zrosenfeld (Rodrigo Rosenfeld Rosas)rr.rosas@gmail.com
<ul></ul><p>I'd much prefer something like this and reserve the {a, b} syntax to be used as a shortcut for {a: a, b: b} like in CoffeeScript in the future...</p>
<p>Also, I find it clearer to read as well</p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=283772012-07-24T12:01:40Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Feedback</i></li><li><strong>Assignee</strong> deleted (<del><i>matz (Yukihiro Matsumoto)</i></del>)</li></ul><p>This request won't progress without a working proof-of-concept. Feel free to send us your pull request. <a href="https://github.com/ruby/ruby" class="external">https://github.com/ruby/ruby</a></p> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=315242012-10-25T18:43:21Zyhara (Yutaka HARA)
<ul><li><strong>Target version</strong> changed from <i>2.0.0</i> to <i>3.0</i></li></ul> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=315262012-10-25T18:56:10Zyhara (Yutaka HARA)
<ul><li><strong>Target version</strong> changed from <i>3.0</i> to <i>2.6</i></li></ul> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=687802017-12-25T18:15:05Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Target version</strong> deleted (<del><i>2.6</i></del>)</li></ul> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=940292021-10-06T17:19:55Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Status</strong> changed from <i>Feedback</i> to <i>Closed</i></li></ul><p>This proposal has basically been implemented, with single-line pattern matching and valueless hash creation syntax:</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="n">john</span> <span class="o">=</span> <span class="p">{</span><span class="ss">name: </span><span class="s2">"John"</span><span class="p">,</span> <span class="ss">last: </span><span class="s2">"Smith"</span><span class="p">}</span>
<span class="n">john</span> <span class="o">=></span> <span class="p">{</span><span class="nb">name</span><span class="p">:,</span> <span class="n">last</span><span class="p">:}</span>
<span class="nb">name</span> <span class="c1"># => "John"</span>
<span class="n">last</span> <span class="c1"># => "Smith"</span>
<span class="nb">p</span><span class="p">({</span><span class="nb">name</span><span class="p">:,</span> <span class="n">last</span><span class="p">:})</span>
</code></pre> Ruby master - Feature #6414: Destructuring Assignment https://bugs.ruby-lang.org/issues/6414?journal_id=940412021-10-06T20:32:03Zjeremyevans0 (Jeremy Evans)merch-redmine@jeremyevans.net
<ul><li><strong>Has duplicate</strong> <i><a class="issue tracker-2 status-5 priority-4 priority-default closed" href="/issues/8895">Feature #8895</a>: Destructuring Assignment for Hash</i> added</li></ul>