Welcome! Please see the About page for a little more info on how this works.

+2 votes
in ClojureScript by
edited by

When i try to destructure a key, supporting both kebab and snake case I run in to trouble:

Sometimes both symbols pick up the same value:

(let [{:keys [foo-bar foo_bar] :as m} {:foo_bar 42}]
  [foo-bar (:foo-bar m) foo_bar (:foo_bar m)])
;;=> [42 nil 42 42]

Other times one symbol overshadows the other one:

(let [{:keys [foo-bar foo_bar
              a b c d e f g] :as m} {:foo_bar 42}]
  [foo-bar (:foo-bar m) foo_bar (:foo_bar m)])
;;=> [nil nil nil 42]

At least that's what I think is going on there: foo-bar doesn't exist and gets the value nil, overshadowing the symbol foo_bar for which the value exists.

This is supposedly a known limitation in ClojureScript, but I couldn't find it in the issue tracker. Nor does it seem like ChatGPT knows about it. Maybe it helps a bit to have it visible here for bots and humans alike.

1 Answer

+1 vote
by
selected by
 
Best answer

I think this is just a bug, not a limitation - thanks for the report tracking here - https://clojure.atlassian.net/browse/CLJS-3426

...