cursive

Joe R. Smith 2025-04-04T18:53:45.545519Z

hmm, this is valid Clojure, but Cursive cannot resolve a:

dpsutton 2025-04-04T19:09:23.118009Z

this is undefined and it’s valid to complain i believe

Joe R. Smith 2025-04-04T19:10:01.196789Z

undefined by clojure or by cursive?

Joe R. Smith 2025-04-04T19:10:46.286779Z

it's valid clojure code, a is whatever you pass in as the first arg to blah

dpsutton 2025-04-04T19:11:26.273789Z

trying to find a recent discussion. But the gist is that the or is not suitable for arbitrary expressions, and certainly not with binding forms in the same destructure

Joe R. Smith 2025-04-04T19:12:13.497459Z

not suitable? This has worked in Clojure since the keys sugar was introduced

dpsutton 2025-04-04T19:12:28.632559Z

i think the distinction is works vs well-defined

Joe R. Smith 2025-04-04T19:23:51.062379Z

the defn -> fn* -> maybe-destructured implementation in clojure core is unambiguous. all params in the arg vector have prior ones in lexical scope

Joe R. Smith 2025-04-04T19:24:03.610739Z

(defn ^{:private true}
  maybe-destructured
  [params body]
  (if (every? symbol? params)
    (cons params body)
    (loop [params params
           new-params (with-meta [] (meta params))
           lets []]
      (if params
        (if (symbol? (first params))
          (recur (next params) (conj new-params (first params)) lets)
          (let [gparam (gensym "p__")]
            (recur (next params) (conj new-params gparam)
                   (-> lets (conj (first params)) (conj gparam)))))
        `(~new-params
          (let ~lets
            ~@body))))))

Alex Miller (Clojure team) 2025-04-04T19:44:20.620099Z

I think it’s defined (undefined would be if a was in same destructuring)

Joe R. Smith 2025-04-04T19:45:14.323299Z

^ makes sense to me it'd be undefined if referring to a different binding in the same destructuring map.

raspasov 2025-04-04T23:05:44.857839Z

Oh wow, I never realized this is valid Clojure… 🙂 Even this seems to work, but perhaps by accident?

(defn abc [a {:keys [b c] :or {b a c b}}]
  (* a b c)) 

(comment
  (abc 3 {}) ;=> 27
 )

dpsutton 2025-04-04T23:06:49.107609Z

> (undefined would be if a was in same destructuring) in your :keys [b c] there i think you are touching the stove

raspasov 2025-04-04T23:09:12.513109Z

yeah… I would probably avoid this kind of {:or { …}} for clarity purposes… in either case

raspasov 2025-04-04T23:10:45.241589Z

I do use the {:or …} style to provide meaningful defaults but typically they are not related to any other argument of the same fn…

👍 1
grav 2025-04-05T07:58:58.548399Z

Wasn't there something about this working depending on what backing type is used for the hashmap? Or am I imagining that discussion? 😅

😮 1
Alex Miller (Clojure team) 2025-04-05T14:12:31.796089Z

Maps are unordered which is why the order that maps are restructured into bindings is not defined

🎯 3