followup on struct inheritance

2 views
Skip to first unread message

Stuart Halloway

unread,
Oct 7, 2008, 4:57:14 PM10/7/08
to clo...@googlegroups.com
This is a tangent from Brian's question about struct inheritance:
While I am not sure that I want struct inheritance, it seems
unnecessarily hard to write the macro for it. Structs are not first
class citizens, in that you cannot reflect against them. I want to ask:

(defstruct person :fname :lname)
(struct-keys person) ;hypothetical function
-> (:fname, :lname)

Of course, by poking around a little bit I can get the answer:

; reflective goo
(.get (.getDeclaredField (class person) "keys") person)
-> (:fname :lname)

Two questions:

(1) Should Clojure provide a function to reflect on a
PersistentStructMap$Def's keys?
(2) Philosophical question: Why not make fields like Def.keys public
to begin with? They are they key public contract of the Def class
anyway. With keys public I would be comfortable with just saying
(.keys person) for the scenario of reflecting against structure
definitions.

Stuart

Brian Doyle

unread,
Oct 9, 2008, 11:43:35 PM10/9/08
to clo...@googlegroups.com
On Tue, Oct 7, 2008 at 2:57 PM, Stuart Halloway <stuart....@gmail.com> wrote:

This is a tangent from Brian's question about struct inheritance:
While I am not sure that I want struct inheritance, it seems
unnecessarily hard to write the macro for it. Structs are not first
class citizens, in that you cannot reflect against them. I want to ask:

(defstruct person :fname :lname)
(struct-keys person) ;hypothetical function
-> (:fname, :lname)

Of course, by poking around a little bit I can get the answer:

; reflective goo
(.get (.getDeclaredField (class person) "keys") person)
-> (:fname :lname)

Two questions:

(1) Should Clojure provide a function to reflect on a
PersistentStructMap$Def's keys?

I think I found an easy way to get the keys of a struct like:

(keys (struct person))
 
Reply all
Reply to author
Forward
0 new messages