Share your thoughts in the 2025 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureCLR by

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:

 (let [value (when (:key map) (fn (:key map)))]
    (if value (assoc map :key value) map))'
ago by
I tried the following in Clojure 1.12.2 (Windows) and 1.12.3-alpha4 (Windows and Linux):

```
(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}
```

I thought the `p2` and `p3` examples matched the description given and would fail.  They do not.  Could you provide a more specific example that illustrates the problem?   Your description says the error occurs in web handlers?  Does this only occur in that context?

Please log in or register to answer this question.

...