I want to create an object with properties and methods in Clojure, I read that gen-class and proxy can do the job I need but its implementation is very confusing for me.
I want to use proxy to avoid AOT compilation steps, I read about it and I though I better learn how to use the easier of the two
Here is what I want to do in Clojure
Java code:
public class MyClass {
public float myFloat;
MyClass( float _myFloat ) {
myFloat = _myFloat
}
public void showNumber() {
println( myFloat );
}
}
I'm struggling to translate that code to Clojure using proxys, any help will be much appreciated
UPDATE:
Apparently deftype is more suitable for my purposes, but I'm still struggling with its implementation
Here is my Clojure code:
(deftype Particle [x y]
Object
(render [this]
(no-stroke)
(fill 200 30 180)
(ellipse x y 200 200)))
Thing is I need to specify a protocol which I'm not sure which one to use, so I'm using Object as I'm trying to create a java-class like object but I get the folloiwng error message:
Can't define method not in interfaces: render
I'm using quill which is a Processing port for Clojure if that helps
UPDATE 2:
OK I manage to get a working defprotocol and deftype combo, but there is 1 more thing I need to leran how to do and that is to add member variables or properties to my class, here is my clojure code:
(defprotocol ParticleProtocol
(update [this])
(render [this]))
(deftype Particle [position]
ParticleProtocol
(update [this])
(render [this]
(no-stroke)
(fill 200 30 180)
(ellipse (.x position) (.y position) 20 20)))
To this object I would like to add a couple of variables like radius among others, any ideas?