On Tue, Mar 29, 2011 at 16:30, Jonathan Smith
<jonathansmith...@gmail.com> wrote:
> You might want to read through the source of scriptjure:
> https://github.com/arohner/scriptjure
>
> For one way to do this sort of thing. Pretty much, you would make a
> basic recursive descent parser that operates on a tree of clojure
> primitives. You could then wrap this in a macro, and go from there.
>
> Note that there is a lot more similarity between clojure and
> javascript than there is between clojure and java (oddly enough).

I've looked a little at scriptjure. I could see writing a tree walker
for some subset of pseudo-clojure that spits out java code, though it
sounds like a lot of work. I think I'll save that up in case I don't
find another satisfactory approach.

> I also wonder if there is a way to do what you are trying to do
> without emitting text.
> (Possibly by extending the java.lang.Enum class? No idea...)

I thought of that, but didn't pursue the idea because it's useful to
my colleagues to have access to readable source code of the enum
classes. This is particularly relevant because most of these enums
carry not just their identity (i.e. their name()), but also additional
metadata immutable data accessible through final fields on the enum
instances of any given type.

It's useful to have source to look at to see what those values are,
particularly during the refactoring when we're replacing our previous
approach: value objects named uniquely by a pair of strings (the first
being analogous to a class), containing additional data, and loaded
from a database on startup. This turns out to be a unit-testing
nightmare. Unit testing was not considered in the original design of
the system. Replacing these objects with enums will help here.

Also, I was reluctant to go the route of using Clojure to try to roll
my own Enums because I didn't want to inadvertently pull in runtime
dependencies on Clojure. Also, I'd want to imitate what the Java
compiler does so my Enums work just like the "real thing". A potential
source of error.

// Ben

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