Hi,

I modified the gen-struct macro a bit and got it to generate
simple, mutable and immutable structures. You can customize
only one aspect of those classes: their fields. Here's an example:

    (gen-struct
     :name my.test.struct
     :mutable-fields [[float x]
                            [float y]]
     :final-fields [[int timeout]
                      [static int MAX_TIMEOUT :is 1000]
                      [java.io.File input]])

gen-struct automatically generates a constructor which lets you
initialize all the final, non-static fields. In the above example,
single constructor accepting an `int` value and a `File` object would
be generated (you pass the arguments in order in which they were
declared in the macro).

gen-struct classes need to be compiled, just like with gen-class.

This is an ugly duckling, since it doesn’t allow for inheritance (not
planning to add it right now),
probably not everyone will be satisfied with no possibility of
overriding equals method,
and static final fields can only be of primitive type.
At least it doesn’t let you mix state and behavior in one entity.

My main motivation for creating it was that some of my experiments in
clj-processing needed a lot of mutation.

Here's the source:

    http://github.com/rosado/gen-struct/tree/clean

Roland

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to