Basically, destructuring allows you to create local bindings in a very succint (and elegant) syntax.
In this article, we will demonstrate the basics of destructuring in clojure, usingKLIPSE.
Destructuring a vector
The simplest example is destructuring the first
n values of a vector:
A more advanced example is splitting a vector into a
head and a
It’s also worth noting that you can bind the entire vector to a local using the
Destructuring a map
Simple destructuring on a map is as easy as choosing a local name and providing the key.
As the example shows, the values of
:y are bound to locals with the names
Usually, you want to create locals with the same name as the keys of the map.
In this case, the syntax becomes even simpler, using the
As with vectors, you can bind the entire map to a local using the
Here is how to combine
In the next article, we will show more advanced usages og destructuring in clojure.