Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Clojure Destructuring Tutorial and Cheat Sheet (gist.github.com)
75 points by falava on Aug 3, 2014 | hide | past | favorite | 5 comments


This is great, and it is also worth reading "Destructuring in Clojure and Ruby":

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-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


I 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/Refe...), too, and is very pleasant to use. I hope it makes it into the ECMAScript 6 standard.


Your hopes shan't be dashed! Destructuring assignment is part of the ES6 specification now: http://wiki.ecmascript.org/doku.php?id=harmony:destructuring


Instead 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.


This is exactly what I was looking for after I reached minimal competency just to finish the exercises on the 'koans' site.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: