clojure-dev 2026-10-25

Alex Miller (Clojure team) 2026-10-25T12:01:29.276449Z

Not quite sure what you're asking, but I think the example in the image makes sense to me as a good use of selector

If the new destructuring features are for data validation and documentation, I am not sure if it is good to use them also for simple data manipulation like here. It is very practical. But for me the syntax here looks a bit like an abuse. For example :select _ is unusual. We create something, with _ we suggest it is thrown away, but then it is recovered and returned through a back channel. Returning a function is also unusual. If I needed a function for map I would prefer partial, but not always work with intermediate functions.

Alex Miller (Clojure team) 2026-10-25T14:32:12.273849Z

Well if you find _ is suggesting the wrong thing here, then name it something :). Returning functions is a normal higher order thing to do (partial, juxt, comp)

➕ 1

(map (selector {:keys [a b] :or {:a 0 :b 0} :select enriched}) data)

Is this intentional?

((selector {{x :x} :u :keys! [u] :select _}) {:u 3})
=> {:u {}}
And if you add :excess it crashes. I guess it is a bug. But I could not imagine what the correct behaviour should be.

user=> (let [{{x :x} :u} {:u 3}] [x])
[nil]
user=> (let [{{x :x} :u :select s} {:u 3}] [x s])
[nil {:u {}}]
user=> (let [{{x :x} :u :select s :excess e} {:u 3}] [x s e])
Execution error (ClassCastException) at user/eval260 (REPL:1).
class java.lang.Long cannot be cast to class clojure.lang.IPersistentMap (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IPersistentMap is in unnamed module of loader 'app')

The implication here in all of these is that you're destructuring a Long (`3`) against a hash map (`{x :x}`).

I'm not surprised the third form fails, to be honest. I'm more surprised that the second form does not fail.

➕ 1

The first form behaves the same in 1.12 and 1.13 and that's much more about this:

user=> (get 3 :x)
nil

➕ 1
Alex Miller (Clojure team) 2026-10-25T23:18:30.652809Z

I'd say associative destructuring of a non associative value is undefined

👍🏻 1
☝️ 1