Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble understanding :state in Clojure

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)

like image 575
Rayne Avatar asked Jan 23 '23 10:01

Rayne


1 Answers

: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.

like image 127
Jeff Foster Avatar answered Feb 01 '23 23:02

Jeff Foster