Did you know that, when using associative destructuring in Clojure (not {:keys [my keys]}), you can use normal functions to compute the keys ?
(let [{value (inc 0)} {1 :a}] ;; (inc 0) => 1 => key in the map {1 :a}
value)
Never seen this anywhere, I’ve just tried and it worked. I don’t know if it’s officially supported or not, good practice or not etc. What do you think ?
I suppose that in the destructuring part {value :a}, the Clojure compiler says "Hey, I need the value for :a in the map {:a 1}: (get {:a 1} :a)". Since the destructuring syntax works like a normal “mini-let” binding (the key in the map {value :a} is the symbol to bind the value to), the value, like a let binding, can be any valid Clojure expression.
In clojure let is a macro that transforms into a call to the let* special form after some preprocessing. This allows us to use macroexpand to find out what’s going on:
… the funky gensym-generated names, like map__14199, are created by the destructure function, which is used by the various functions/macros that support this sort of thing. The source for that is in clojure.core if you want to have a look.