This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-09
Channels
- # announcements (3)
- # babashka (63)
- # beginners (55)
- # calva (14)
- # cider (12)
- # clj-commons (20)
- # clj-kondo (22)
- # clojure (149)
- # clojure-europe (4)
- # clojurescript (25)
- # community-development (3)
- # conjure (9)
- # datomic (5)
- # emacs (2)
- # fulcro (2)
- # hyperfiddle (6)
- # lsp (23)
- # nbb (4)
- # pedestal (2)
- # reagent (26)
- # releases (3)
- # sql (3)
- # xtdb (6)
Following on from a discussion in #C03S1KBA2 I would like to see clj-kondo
flag this as problematic code:
(defn panda
[& {:keys [a b c d e f g h]
:or {a 1
b a
c b
d c
e d
f e
g f
h g}}]
[a b c d e f g h])
(defn sad-panda
[& {:keys [a b c d e f g h i]
:or {a 1
b a
c b
d c
e d
f e
g f
h g
i h}}]
[a b c d e f g h i])
The first fn works by accident as the defaults map is small and uses an array map so the keys stay in order and defaults can depend on earlier ones. The second fn fails because the defaults map is larger and uses a hash map and so the keys are in a different order. This has come up before and I'm pretty sure Alex confirmed that this was never intended to work -- it's just an accident of implementation in the small case.
Could clj-kondo
detect that the default values are depending on each other?Is that this issue? Feel free to upvote: https://github.com/clj-kondo/clj-kondo/issues/916
Added a š:skin-tone-2: Interesting group of related issues there around destructuring. Sorry I didn't just search the open issues before commenting š
The burden of popularity š
Oooooh this is a brain tickler. I might give this a go, intrigued by how Iād go about it.
:or-local-binding
, :or-non-local-binding
, :or-bindings
, :or-expression-bindings
, etc
:self-referential-default-bindings
lol
I think the issue is now beyond self-referential bindings, any destructured binding (from the same map) in defaults is considered undefined now
or maybe :self-referential-destructured-bindings
because any sort of self-reference is undefined
i'm using self-referential to mean "from the same map". i don't have a good phrase at hand that means the same
(just in case, i love these bikeshedding discussions but if you find something you like, you don't need to idk get my permission or blessing lol)
undefined-default is pithy and short but doesn't tell me what exactly it's protecting against unless I already know the error
I'll wait for @U04V70XH6 to throw in a good name suggestion as well
After several of the suggestions here, I have nothing š