News for hackers. Stuff that matters.
Re:ES6 in Depth: Destructuring by thomasvarney723 on Thursday May 28, 2015 @11:03PM (#9622467)
I recognize destructuring from Clojure. Did it origniate there? Or is this a specific case of pattern matching?
Re:ES6 in Depth: Destructuring by bshimmin on Friday May 29, 2015 @02:54AM (#9623126)
Other languages have this too, eg. Ruby:

  a, b = [1, 2]
  a, b = {:a => 1, :b => 2}
Similarly in Python, at least for the array example (there's probably some way of destructuring a dictionary in Python, but I don't know it myself).

PHP also has `list()`...

Re:ES6 in Depth: Destructuring by petepete on Friday May 29, 2015 @07:25AM (#9623901)
For arrays, yes, but that won't work for Ruby hashes (which aren't ordered):

    [1] pry ~ »  a, b = {a: 1, b: 2}
    {
        :a => 1,
        :b => 2
    }
    [2] pry ~ »  a
    {
        :a => 1,
        :b => 2
    }
    [3] pry ~ »  b
    nil
Re:ES6 in Depth: Destructuring by bshimmin on Friday May 29, 2015 @07:45AM (#9623965)
You're quite right, I meant to add `values_at` in the hash example! And the syntax is still not so nice:

  irb(main):005:0> a, b = {:a => 1, :b => 2}.values_at(:a, :b)
  => [1, 2]
Or:

  irb(main):006:0> a, b = (h = {:a => 1, :b => 2}).values_at(*h.keys)
  => [1, 2]
Edit: Ruby's hashes are ordered since 1.9, incidentally.
Re:ES6 in Depth: Destructuring by petepete on Friday May 29, 2015 @11:17AM (#9625068)
a, b = {a: 1, b: 2}.values
Re:ES6 in Depth: Destructuring by nahiluhmot on Thursday May 28, 2015 @11:11PM (#9622485)
Common Lisp also has destructuring-bind[0], although its not provided with every implementation.

[0] https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node252.html

Re:ES6 in Depth: Destructuring by nbouscal on Friday May 29, 2015 @06:44AM (#9623779)
It's basically just pattern matching. Similar things have been around since at least the 70s (e.g. in SASL).
Re:ES6 in Depth: Destructuring by btbuildem on Friday May 29, 2015 @11:22AM (#9625101)
Erlang and Python have destructuring as well - it's a pretty established shorthand.