binding lose value in map fn

Description

(def ^:dynamic ca false)

(binding [ca true]
(prn "now:" ca)
(map #(prn "now2:" ca %) [1 2 3])
)

onedam.testfeng - "now:" true - INFO [2019-05-13 18:24:55.826]
onedam.testfeng - "now2:" false 1 - INFO [2019-05-13 18:24:55.826]
onedam.testfeng - "now2:" false 2 - INFO [2019-05-13 18:24:55.826]
onedam.testfeng - "now2:" false 3 - INFO [2019-05-13 18:24:55.826]

Environment

clojure 1.10 jdk 1.8

Activity

Show:
中小 行者
May 14, 2019, 7:58 AM

tks

David Bürgin
May 14, 2019, 7:24 AM

map is lazy, so your seq is not realised until after it has left scope of binding, see eg https://cemerick.com/2009/11/03/be-mindful-of-clojures-binding/.

Completed
Your pinned fields
Click on the next to a field label to start pinning.

Assignee

Unassigned

Reporter

中小 行者

Priority

Major

Affects versions

Fix versions