Re: Example to introspect a class
Thank you I'm still learning all the different forms so this is very helpful. On Apr 1, 10:13 pm, Ken Wesson kwess...@gmail.com wrote: On Fri, Apr 1, 2011 at 10:56 AM, Mushfaque Chowdhury mushfaque.chowdh...@googlemail.com wrote: Hi I'm trying to solve a introspection problem of the following type (def Region {'fields '((datatype x) (datatype y))}) (def Country {'fields '((int x) (double y {reference `Region}))}) I'd like to introspect the fields from Country and see {reference Region} replaced by (reference ((datatype x) (datatype y))) I can get as far as seeing this ((nth (nth (Country 'fields) 1) 2) 'reference) which gives (quote com.test.Common/Region) which is sort of close, but how do I now look at it's fields? First of all, that's not actually a class, it's a var. Second, does it actually need to be quoted a second level? Third, (second '(quote com.test.Common/Region)) will be the symbol com.test.Common/Region, and if you get that symbol into a local named foo, (ns-resolve *ns* foo) ought to yield up a Var object. And (@that-var 'fiels} then ought to cough up '((datatype x) (datatype y)). Indeed: user= (def Region {'fields '((datatype x) (datatype y))}) #'user/Region user= (def Country {'fields '((int x) (double y {reference `Region}))}) #'user/Country user= (@(ns-resolve (find-ns 'user) (nth ((nth (nth (Country 'fields) 1) 2) 'reference) 1)) 'fields) ((datatype x) (datatype y)) -- 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
Example to introspect a class
Hi I'm trying to solve a introspection problem of the following type (def Region {'fields '((datatype x) (datatype y))}) (def Country {'fields '((int x) (double y {reference `Region}))}) I'd like to introspect the fields from Country and see {reference Region} replaced by (reference ((datatype x) (datatype y))) I can get as far as seeing this ((nth (nth (Country 'fields) 1) 2) 'reference) which gives (quote com.test.Common/Region) which is sort of close, but how do I now look at it's fields? -- 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
Re: Example to introspect a class
You'd have to not back-quote Region and then eval the reseult: user= (def Country {'fields '((int x) (double y {reference Region}))}) #'user/Country user= ((nth (nth (Country 'fields) 1) 2) 'reference) Region user= (eval ((nth (nth (Country 'fields) 1) 2) 'reference) ) {fields ((datatype x) (datatype y))} If you want the contents of Region in Country and not its symbol: (def Country `{fields ((int x) (double y {reference ~Region}))}) and look it up with: ((nth (nth (Country 'fields) 1) 2) 'user/reference) (((nth (nth (Country 'fields) 1) 2) 'user/reference) 'fields) Or to avoid the qualified names: user= (def Country {'fields (list (list 'int 'x) (list 'double 'y {'reference Region}))}) #'user/Country user= ((nth (nth (Country 'fields) 1) 2) 'reference) {fields ((datatype x) (datatype y))} user= (((nth (nth (Country 'fields) 1) 2) 'reference) 'fields) ((datatype x) (datatype y)) On Apr 1, 7:56 am, Mushfaque Chowdhury mushfaque.chowdh...@googlemail.com wrote: Hi I'm trying to solve a introspection problem of the following type (def Region {'fields '((datatype x) (datatype y))}) (def Country {'fields '((int x) (double y {reference `Region}))}) I'd like to introspect the fields from Country and see {reference Region} replaced by (reference ((datatype x) (datatype y))) I can get as far as seeing this ((nth (nth (Country 'fields) 1) 2) 'reference) which gives (quote com.test.Common/Region) which is sort of close, but how do I now look at it's fields? -- 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
Re: Example to introspect a class
On Fri, Apr 1, 2011 at 10:56 AM, Mushfaque Chowdhury mushfaque.chowdh...@googlemail.com wrote: Hi I'm trying to solve a introspection problem of the following type (def Region {'fields '((datatype x) (datatype y))}) (def Country {'fields '((int x) (double y {reference `Region}))}) I'd like to introspect the fields from Country and see {reference Region} replaced by (reference ((datatype x) (datatype y))) I can get as far as seeing this ((nth (nth (Country 'fields) 1) 2) 'reference) which gives (quote com.test.Common/Region) which is sort of close, but how do I now look at it's fields? First of all, that's not actually a class, it's a var. Second, does it actually need to be quoted a second level? Third, (second '(quote com.test.Common/Region)) will be the symbol com.test.Common/Region, and if you get that symbol into a local named foo, (ns-resolve *ns* foo) ought to yield up a Var object. And (@that-var 'fiels} then ought to cough up '((datatype x) (datatype y)). Indeed: user= (def Region {'fields '((datatype x) (datatype y))}) #'user/Region user= (def Country {'fields '((int x) (double y {reference `Region}))}) #'user/Country user= (@(ns-resolve (find-ns 'user) (nth ((nth (nth (Country 'fields) 1) 2) 'reference) 1)) 'fields) ((datatype x) (datatype y)) -- 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