To expand on this: user=> (defn try [] 5) #'user/try user=> (try) ; `try` alone is resolved to the special form nil user=> (#'try) ; obtaining the `try` var works just fine ; (vars currently delegate function calls to their values) 5 user=> (@#'try) ; explicitly deref'ing the fn from the `try` var and invoking it 5
So, you *can* shadow the binding of try (or any special form) within a given namespace, but you also need to resolve the var in question yourself (since regular symbols naming special forms are always given priority without the #' syntax [or use of the `var` macro]). None of that is required for regular functions, the resolution of which always takes into account the current namespace and its interned/referred vars. - Chas On Jan 10, 2011, at 8:51 PM, Stuart Halloway wrote: > Hi Tom, > > "try" is a special form, and "test" is a function. > > Stu > >> I know I should not be naming my functions the same thing as ones in >> core but was surprised when I wrote the following >> https://github.com/thattommyhall/tth-SICP/blob/master/1-35.clj >> I have being doing the SICP stuff in clojure and accieently copied >> "try" as the fn name and it did not work, I noticed a colleague chose >> "test" and it did work, but test is in core too so I don't get the >> difference. >> >> Playing around on the repl I get >> user> (defn try [] ()) >> #'user/try >> user> (defn test [] ()) >> WARNING: test already refers to: #'clojure.core/test in namespace: >> user, being replaced by: #'user/test >> #'user/test >> user> (try 1) >> 1 >> user> (test 1) >> Throws "Wrong number of args (1) passed to: user$test" (as you would >> expect from my defn of test) >> >> user> (user/try 1) >> and >> user> (user/test 1) >> both >> throw the error. >> >> >> Why can test be shadowed and not try? Am I missing something? >> >> Tom >> >> -- >> 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 > > -- > 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 -- 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