creating classes in Clojure

4 views
Skip to first unread message

fft1976

unread,
Aug 10, 2009, 10:31:47 PM8/10/09
to Clojure
Is there a way to create a Java class (not instance) in Clojure
without writing actual Java? e.g.

public class person {
public string name;
public int num_children;
public double weight;
}

Kyle R. Burton

unread,
Aug 10, 2009, 10:53:31 PM8/10/09
to clo...@googlegroups.com

Yes, tho perhaps not according to the example you have there. You can
complie a clojure file by using gen-class:

http://clojure.org/compilation

gen-class does support a state declaration, but it doesn't seem to map
cleanly to member variables as in your example. What is probably more
idiomatic on the clojure side is to use a map for such a data object.

I wrote up an example that uses gen-class and ant to create executable
jars here:

http://asymmetrical-view.com/2009/06/22/executable-clojure-jars.html

Regards,

Kyle Burton

Reply all
Reply to author
Forward
0 new messages