Clojure binding of dynamic var not working as expected

后端 未结 3 1370
一生所求
一生所求 2020-12-11 20:53

From what I understand, setting a new binding on a dynamic var affects all functions called within that binding, and all functions called from those functions.

Why d

3条回答
  •  借酒劲吻你
    2020-12-11 21:33

    This is caused by lazyness - map returns a lazy sequence which is defined inside the binding but is evaluated outside. You need to force the evaluation from inside:

    (binding [*out-dir* "/home/dave"] 
      (doall (map #(str *out-dir* %) [1 2 3])))
    

提交回复
热议问题