Binding 装订及;pmap交互更改?

Binding 装订及;pmap交互更改?,binding,clojure,thread-local,dynamic-variables,pmap,Binding,Clojure,Thread Local,Dynamic Variables,Pmap,有几篇有点老的博文建议在混合动态变量、binding和pmap时要小心,例如,我们从中得到以下代码片段: user=> (def *foo* 5) #'user/*foo* user=> (defn adder [param] (+ *foo* param)) #'user/adder user=> (binding [*foo* 10] (doseq [v (pmap adder (repeat 3 5))

有几篇有点老的博文建议在混合动态变量、
binding
pmap
时要小心,例如,我们从中得到以下代码片段:

user=> (def *foo* 5)
#'user/*foo*
user=> (defn adder
             [param]
             (+ *foo* param))
#'user/adder
user=> (binding [*foo* 10]
         (doseq [v (pmap adder (repeat 3 5))]
           (println v)))
10
10
10
nil

但当我运行该代码时,情况并非如此(将第一行更改为
(def^:dynamic*foo*5)
)。我得到三个
15
s作为输出(使用Clojure 1.4),正如您天真地期望的那样,通过传递给pmap的函数可以看到绑定形式的变化。线程本地绑定和pmap交互的方式是否已更改?我在任何地方都找不到此文档。

从1.3开始,本地绑定集随函数一起发送到pmap。因此,只要您标记var^:dynamic,这就不再是一个问题。此功能称为绑定传输,包含在1.3变更日志中:

发件人:

将工作传递给其他线程(例如发送、发送、pmap、未来)的Clojure API现在传递调用线程的动态绑定: (定义^:动态*num*1) (绑定[*num*2](未来(println*num*)) ;; 打印“2”,而不是“1”
谢谢这在哪里有记录?它不在里面 Clojure APIs that pass work off to other threads (e.g. send, send-off, pmap, future) now convey the dynamic bindings of the calling thread: (def ^:dynamic *num* 1) (binding [*num* 2] (future (println *num*))) ;; prints "2", not "1"