Destructuring is a feature in Clojure that is not common in other lisps; the idea is to allow you to write more concise code in scenarios where code doesn't really add value (for example, getting the first element from a list or the second parameter from a function) and concentrating only on what is important to you.
In order to understand this better, let's see an example of why destructuring can help you:
(let [v [1 2 3]] [(first v) (nth v 2)]) ;; [1 3]
What's wrong with the previous code? Nothing really, but you need to start thinking about what is v
, what the first value of v
is, what the nth function does, and at what index v
starts.
Instead we can do this:
(let [[f s t] [1 2 3]] [f t]) ;; [1 3]
Once you are used to destructuring, you will see that you don't need to think about how to get the elements you need. In this case, we directly access the first, second, and third elements from our vector and use the first and third out of the three elements. With good naming...