Skip to content

Instantly share code, notes, and snippets.

@xiongtx
Created April 7, 2017 21:49
Show Gist options
  • Save xiongtx/8095beb4fe80c1af3722dd97ad1d93a0 to your computer and use it in GitHub Desktop.
Save xiongtx/8095beb4fe80c1af3722dd97ad1d93a0 to your computer and use it in GitHub Desktop.
`with-redefs` problems with laziness
(defn two-deep [_]
"two-deep")
(defn other-two-deep [_]
"other-two-deep")
(defn one-deep [& args]
(map two-deep args))
(defn foo []
(map one-deep (range 0 3)))
(with-redefs [two-deep other-two-deep]
(foo))
;; => (("two-deep") ("two-deep") ("two-deep"))
(with-redefs [two-deep other-two-deep]
(doall (foo)))
;; => (("other-two-deep") ("other-two-deep") ("other-two-deep"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment