Title: Threading macro with update and when produces incorrect results
Environment:
- ClojureCLR version: 1.12.2
- .NET version: 10
- OS: MacOS 26.1
Description:
The pattern (-> map (update :key #(when % (fn %)))) fails in ClojureCLR
but works correctly in Clojure JVM. When chaining multiple updates in a
threading macro where the anonymous function contains when, the result
is incorrect or causes runtime errors.
Expected Behavior:
Should work identically to Clojure JVM - update with a function that
returns nil should associate nil to the key.
Actual Behavior:
[Crashes/Wrong values/500 errors in web handlers]
Workaround:
Use explicit conditionals instead:
`clojure
(let [value (when (:key map) (fn (:key map)))]
(if value (assoc map :key value) map))
I think I need some more detail to get to a fail. I was thinking from your description that one or more of these might fail:
(def p1 {:name "James" :age 26})
(def p2 {:name "Fred" :age nil})
(def p3 {:name "Fred"})
(-> p1 (update :age #(when % (inc %)))) ; => {:name "James", :age 27}
(-> p2 (update :age #(when % (inc %)))) ; => {:name "Fred", :age nil}
(-> p3 (update :age #(when % (inc %)))) ; => {:name "Fred", :age nil}
They do not fail. (I tested under CLojureCLR version 1.12.2 and 1.12.3-alpha4).
I thought the p2 and p3 cases would match with 'a function that returns nil should associate nil with the key.
Could you provide a more specific example that illustrates the problem?Thanks for your help. I’ll get back to you shortly with a more specific example that illustrates the problem.
@madeinquant FYI ClojureCLR issues can be reported at http://ask.clojure.org (which is the standard way to report all issues against all projects under the clojure GitHub organization).
Thank you