Advanced destructuring and namespaces
In this section, we'll dig further into ClojureScript's destructuring syntax. We'll also learn about ClojureScript namespaces. If you're familiar with JavaScript ES6 modules, namespaces are sort of akin to that-they're essentially modules within which variable and function definitions are located and a collection of imported libraries can be defined, often with local bindings for convenience.
Destructuring
Destructuring in ClojureScript provides a way of binding values to local variables. We've already seen a few simple examples of how this works with the code in previous sections, but destructuring in ClojureScript is extremely powerful and so comprehensive that it's worth looking at some more advanced patterns of it.
First, let's try destructuring the vector [1 2]
:
cljs.user=> (let [[a b] [1 2]] (+ a b)) ;; => 3
The same destructuring logic works in a nested fashion:
cljs.user=> (let [[[a b] c] [[1 2] 3...