On a related note, can someone explain the following... I can define a function 'p1':
user=> (defn p1 [x] (+ 1 x)) #'user/p1 user=> (p1 44) 45 and then shadow it within the binding construct: user=> (binding [p1 (fn [y] (+ 2 y))] (p1 44)) 46 but, I can't seem to do this with the 'inc' function: user=> (binding [inc (fn [y] (+ 2 y))] (inc 44)) 45 Why doesn't this work? Stephen said previously "The binding form operates on the var, it doesn't affect name resolution within the binding form's body" so the (inc 44) must resolve to clojure.core/inc: user=> (binding [inc (fn [y] (+ 2 y))] (resolve 'inc)) #'clojure.core/inc but, is there a way to shadow the var pointed to by clojure.core/inc? Neither of the following works: user=> (binding [#'clojure.core/inc (fn [y] (+ 2 y))] (inc 44)) java.lang.ClassCastException: clojure.lang.Cons (NO_SOURCE_FILE:22) user=> (binding [clojure.core/inc (fn [y] (+ 2 y))] (clojure.core/inc 44)) 45 Any help untangling the concepts of vars, namespaces, and binding interactions is appreciated, -tom On Dec 19, 5:21 pm, "Stephen C. Gilardi" <squee...@mac.com> wrote: > On Dec 19, 2009, at 5:23 PM, Stefan Kamphausen wrote: > > > 1. Is my explanation correct? > > It is. The binding form operates on the var, it doesn't affect name > resolution within the binding form's body. *val* within the body of the > binding still resolves to the let-bound local. While *val* is shadowed by a > let-bound local, if you want to refer to the var *val*, use its fully > qualified name. > > > 2. Is this the desired behavior or will it change in the near future? > > This behavior is well-established. I have no special knowledge of what may or > may not change, but changing this behavior seems very unlikely to me. > > --Steve -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en