Fork me on GitHub
#clj-kondo
<
2023-11-27
>
cl_j15:11:13

clj-kondo gives an error for the following destructuring 🙂

(let [{a :a
         va a} ;; <<- Unresolved symbol: a [unresolved-symbol]
        {:a "value-of-a"
         "value-of-a" :b}]
    va)
  ;; =>	:b

borkdude15:11:24

Rightly so, since maps aren’t ordered you should never rely on this

👍 1
cl_j15:11:58

not sure how this relates to the ordering of maps? From the result of the macroexpand, it seems it does not depend on the ordering,

(let*
 [map__155836
  {:a "value-of-a", "value-of-a" :b}
  map__155836
  (if
   (clojure.core/seq? map__155836)
   (if
    (clojure.core/next map__155836)
    (clojure.lang.PersistentArrayMap/createAsIfByAssoc
     (clojure.core/to-array map__155836))
    (if
     (clojure.core/seq map__155836)
     (clojure.core/first map__155836)
     clojure.lang.PersistentArrayMap/EMPTY))
   map__155836)
  a
  (clojure.core/get map__155836 :a)
  va
  (clojure.core/get map__155836 a)]
 va)  

cl_j15:11:42

thanks @U04V15CAJ it indeed depends on the ordering!

(let [{va a
            a :a}
           {:a "value-of-a"
            "value-of-a" :b}]
       va) ;; => error

👍 1
Noah Bogart15:11:14

It could also expand to “let [… va (get map_123 a) a (get map_123 :a)]”

👍 1