5 ms·
Clojure Destructuring Tutorial and Cheat Sheet
- lkrubner 12y agoThis is great, and it is also worth reading "Destructuring in Clojure and Ruby": http://eyeofthesquid.com/blog/2013/09/29/destructing-in-ruby-and-clojure/ http://eyeofthesquid.com/blog/2013/09/29/destructing-in-ruby... which has some great comparisons. As it says: "As with many things in Ruby, the better question than “Can it be done this way?” is “Is it wise?”. " There is a lot that you can do in Ruby that is more gracefully done in Clojure. Brian Carper brings this out even more clearly with his post "Keyword Arguments: Ruby, Clojure, Common Lisp": http://briancarper.net/blog/579/keyword-arguments-ruby-clojure-common-lisp http://briancarper.net/blog/579/keyword-arguments-ruby-cloju... That post shows the exact point where keyword arguments in Ruby can become ambiguous, which is the exact moment that Clojure's clarity becomes obvious. Also, Jay Field's post on the subject of Clojure destructuring is where I got a lot of practical starting ideas (such as using the :keys directive): http://blog.jayfields.com/2010/07/clojure-destructuring.html http://blog.jayfields.com/2010/07/clojure-destructuring.html
- arthuredelstein 12y agoI first learned about destructuring through Clojure. Lately I've been working on a Firefox extension and discovered that Firefox JavaScript 1.6 supports destructuring (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...), too, and is very pleasant to use. I hope it makes it into the ECMAScript 6 standard.
- pselbert 12y agoYour hopes shan't be dashed! Destructuring assignment is part of the ES6 specification now: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
- spacemanmatt 12y agoThis is exactly what I was looking for after I reached minimal competency just to finish the exercises on the 'koans' site.
- Totient 12y agoInstead of "rest" (which the author mentions is a core function), the Clojure convention for getting the remaining items appears to be "more"; e.g. [x y & more] I really like this tutorial.