Created
June 23, 2013 10:21
-
-
Save thash/5844523 to your computer and use it in GitHub Desktop.
Clojureのbindingとletの違い
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (def ^:dynamic foo 10) | |
| (let [foo 9999] (println foo)) ;;=> 9999 | |
| (binding [foo 9999] (println foo)) ;;=> 9999 | |
| (defn print-foo [] (println foo)) | |
| (let [foo 9999] (print-foo)) ;;=> 10 | |
| (binding [foo 9999] (print-foo)) ;;=> 9999 | |
| ;; ふつうにdefするとdynamic varじゃないので怒られる | |
| (def foo 10) | |
| (binding [foo 9999] (print-foo)) | |
| IllegalStateException Can't dynamically bind non-dynamic var: user/foo clojure.lang.Var.pushThreadBindings (Var.java:353) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment