Fork me on GitHub

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?


I think it's a similar but not exactly the same issue


Maybe add a comment to the issue


Added a 👍:skin-tone-2: Interesting group of related issues there around destructuring. Sorry I didn't just search the open issues before commenting 😕


No problem, there are so many :)


The burden of popularity 🙂

Noah Bogart20:10:11

Oooooh this is a brain tickler. I might give this a go, intrigued by how I’d go about it.


It's fairly easy to implement


Probably the hardest part is a good name. Suggestions welcome :)

😂 1
Noah Bogart21:10:59

:or-local-binding, :or-non-local-binding, :or-bindings, :or-expression-bindings, etc



Noah Bogart14:10:57

: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

Noah Bogart14:10:03

or maybe :self-referential-destructured-bindings because any sort of self-reference is undefined


Keep trying :)

Noah Bogart14:10:13

i'm using self-referential to mean "from the same map". i don't have a good phrase at hand that means the same



Noah Bogart14:10:38

(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)

Noah Bogart14:10:09

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 😆