Access static information of records?

27 views
Skip to first unread message

Michael Jerger

unread,
Apr 5, 2011, 11:56:52 AM4/5/11
to clo...@googlegroups.com
Hi all,

I'm currntly writing a build system based on clojure. On this way I defined a
record called Dependency:

(defrecord Dependency [aspect project runtime dev transitive]
...)

Lateron I try to create lib directories (lib/aspect, lib/project, lib/runtime
...). So it would be nice, if there is a possibility to express this based on
the above defined record keys - sth. like:

(doseq [mykey (keys Dependency)]
(ant/mkdir {:dir (str lib "/" (name mykey))}))

Is there a nifty way in clojure to access such "static record information"?


Kind regards,
Michael
--
Informatikbüro Jerger http://www.jerger.org
Zeppelinstr. 13, D-72770 Reutlingen

fon: +49-7121-578913 mob: +49-178-8189878

signature.asc

Meikel Brandmeyer

unread,
Apr 5, 2011, 1:57:08 PM4/5/11
to clo...@googlegroups.com
Hi,

Am 05.04.2011 um 17:56 schrieb Michael Jerger:

> (doseq [mykey (keys Dependency)]
> (ant/mkdir {:dir (str lib "/" (name mykey))}))
>
> Is there a nifty way in clojure to access such "static record information"?

You can get it from instances of the record type.

user=> (defrecord Dependency [aspect project runtime dev transitive])
user.Dependency
user=> (doseq [mykey (keys (Dependency. 1 2 3 4 5))] (println mykey))
:aspect
:project
:runtime
:dev
:transitive

Otherwise, I'm not aware of such functionality other than reflection.

Sincerely
Meikel

Stuart Sierra

unread,
Apr 5, 2011, 5:53:56 PM4/5/11
to clo...@googlegroups.com
defrecord does not, at present, produce a first-class Clojure object, just a Java class that implements Clojure's map interfaces.  So there's no "Record" object to ask questions about.  As Meikel said, you could use Java reflection, but that's it.

There is some ongoing work to make records more first-class, although I'm not sure if this feature will be included.  See http://dev.clojure.org/display/design/defrecord+improvements

-Stuart Sierra
clojure.com

Michael Jerger

unread,
Apr 6, 2011, 2:19:48 AM4/6/11
to clo...@googlegroups.com
Am Dienstag, 5. April 2011, 23:53:56 schrieb Stuart Sierra:
> defrecord does not, at present, produce a first-class Clojure object, just
> a Java class that implements Clojure's map interfaces. So there's no
> "Record" object to ask questions about. As Meikel said, you could use
> Java reflection, but that's it.

Creating an temporal instance I would not denot as the upright way ...

> There is some ongoing work to make records more first-class, although I'm
> not sure if this feature will be included. See
> http://dev.clojure.org/display/design/defrecord+improvements

At the factory Part I totaly agree :-)
Not geting a first class Clojure object means, that it would not be possible,
to get my static info into and out of the records meta (^#)?
As straightforwad I expect to extend defrecord in order to put my information
into the record-types meta object und get the data out of this after ...

Would this work? Now? In fututre?


Kind regards,
M.Jerger

signature.asc
Reply all
Reply to author
Forward
0 new messages