Skip to content

Instantly share code, notes, and snippets.

@thash
Created June 23, 2013 10:21
Show Gist options
  • Select an option

  • Save thash/5844523 to your computer and use it in GitHub Desktop.

Select an option

Save thash/5844523 to your computer and use it in GitHub Desktop.
Clojureのbindingとletの違い
(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