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:
David Bürgin
May 14, 2019, 5:24 PM

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/.

中小 行者
May 14, 2019, 5:58 PM

tks

Completed

Assignee

Unassigned

Reporter

中小 行者

Labels

None

Approval

None

Patch

None

Fix versions

Affects versions

Priority

Major