views:

162

answers:

2

I understand what :state /does/. It creates a field, like in Java, in your class. What I don't understand is what is the point of this? It seems like I only see it done with Clojure-generated classes that extend other classes. http://www.fatvat.co.uk/2009/05/clojure-and-robocode.html being one example. I don't know Java, and I'm not very well versed in Object Oriented Programming. Can someone explain the point of :state to me, and where it all fits in with Java interop?

Thanks a lot!

NOTE: When I say :state, I am referring to (:gen-class :state)

A: 

I talked it over with hiredman on the #Clojure IRC channel, and he told me that the main point of it is a state per instance. That makes sense.

Rayne
+2  A: 

:state is simply a way of sharing some data between the functions generated as part of gen-class. Think of it as being exactly the same as the instance data of an object.

Jeff Foster