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

0 votes
ago in ClojureScript by
edited ago 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 "7424.6105625"}]
  [foo-bar (:foo-bar m) foo_bar (:foo_bar m)])
;;=> ["7424.6105625" nil "7424.6105625" "7424.6105625"]

Other times one one symbol overshadows the other one:

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

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.

Please log in or register to answer this question.

...