There's one other construct that may help you here:
(defrecord Point [x y]
(scale [this amount]
(assoc this :x (* x amount) :y (* y amount
defrecord acts much like deftype, but creates a new copy of the record via
assoc, you can also do stuff like:
(:x (->Point 10 11))
defrecord creat
Hello Timothy,
Thank you for the response. I've given much thought to your examples and it
quickly became clear how relevant defprotocol and deftype is. I had no idea
Clojure provided a mechanism for strongly typed structures like that. I've
started re-designing my library around this concept a
defstruct is deprecated. You should use defrecord or deftype instead. You
can define operations on these via defprotocol.
And you can even type hint the members:
(defprotocol IScale
(scale [this ^double amount]))
(deftype Point [^double x ^double y]
IScale
(scale [this amount]
(Point.