Hi Zach,
I really love your book!
A question related to the remark about with-redefs at the end of the section: "No one should have to know you’ve used binding".
The remark is: "However, any dynamic var invites re-binding;
it may be safer to use with-redefs instead."
Can you clarify the difference between binding and with-redefs. I understand that with-redefs work also with non-dyanmic vars, but I don't understand in what cases with-redefs is safer than binding.
I have made for myself a minimal code snippet to see the danger of binding in combination with lazy sequences:
user=> (def ^:dynamic *a* 88)
#'user/*a*
user=> (def b (binding [*a* 1] (map (fn [_] *a*) [1 2 3])))
#'user/b
user=> b
(88 88 88)
But the issue also occur with with-redefs:
user=> (def a 88)
#'user/a
user=> (def b (with-redefs [*a* 1] (map (fn [_] *a*) [1 2 3])))
#'user/b
user=> b
(88 88 88)
My question is: in what cases with-redefs is safer than binding?