
Clojure Destructuring Tutorial and Cheat Sheet - falava
https://gist.github.com/john2x/e1dca953548bfdfb9844
======
lkrubner
This is great, and it is also worth reading "Destructuring in Clojure and
Ruby":

[http://eyeofthesquid.com/blog/2013/09/29/destructing-in-
ruby...](http://eyeofthesquid.com/blog/2013/09/29/destructing-in-ruby-and-
clojure/)

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...](http://briancarper.net/blog/579/keyword-arguments-ruby-clojure-
common-lisp)

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
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...](https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)), too,
and is very pleasant to use. I hope it makes it into the ECMAScript 6
standard.

~~~
pselbert
Your 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)

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

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

