On Wed, Feb 29, 2012 at 5:12 PM, Frank Wilson <fajwil...@gmail.com> wrote: > Hi, > > The behaviour of resolve for named functions seems pretty clear to me: > > (resolve 'xyz) > > returns nil (when xyz has not been defined). > > and > > (defn xyz [x] 1) > > (resolve 'xyz) > > returns #'user/xyz (when xyz is defined) > > However if I try to define types: > > (defprotocol Named > (fullName [Named])) > > > (deftype Person [firstName lastName favoriteColor] > Named > (fullName [_] (str firstName " " lastName))) > > Why do the following return nil? > > (resolve '.fullName) > > or > > (resolve '.firstName) > > > What should I be using to check that the symbol .firstName and > .fullName are defined in the current scope? > > (I am trying to write compile-time code the filters/selects undefined > symbols from a chunk of quoted code. > I'd like this to work for both function symbols and method symbols.) > > I'm using clojure 1.3 > > Thanks, > > Frank
There isn't really any way to check if a method name like .foo is "defined". There may or may not be a Java class (including a deftype, defrecord, definterface, or defprotocol) with a .foo method, and any particular such class may or may not have a .foo method. You can check if a specific class or object has a .foo method though, using reflection. With an object, use (.getClass thingy) to get the class. Given a class, you can probe it using various methods of java.lang.Class to see if it has methods with particular names and/or signatures. -- 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