Hello Ben,

On Mar 28, 10:36 pm, B Smith-Mannschott <bsmith.o...@gmail.com> wrote:
> Hi all!
>
> I'm using Clojure to generate java source (enums, specifically) and am
> looking for ideas.
>

I've done this quite a lot in the past using Python to generate C++.
After trying different methods, I used a templating system (Cheetah)
so that the C++ was in separate files with minimal markup (ie it still
looked like C++).

> A small example:
>
> (defn getter
>   [method field type]
>   ["
>     public " (unbox type) " " (name method) "() {
>         return " (name field) ";
>     }\n"])
>


> The templating aspect of all this is solved with constructs Clojure
> already gives me (vectors and plain old clojure expressions), which is
> kind of nice. It's also reasonably friendly for exploratory testing
> and interactive development. Still, I'm not really happy with it.
>

This is very much a personal opinion but I'd disagree with you there.
My guess is that you've put some work into the templating and that you
are ignoring that it might be holding you back (I make this sort of
mistake all of the time which is why I think I recognise it). A famous
film director once said (I can't remember who) something like "you
know you've matured as a film director when you can cut out your
favourite scene because the cut improves the film as a whole".

I'd suggest using a separate text templating system such as:
clojure.contrib.strint [1]
Velocity [2]
StringTemplate [3]

That way you write the Java as Java but replace occasional things with
markup e.g $varname$ and then pump data from Clojure into the
template.

Incidently, I've also used a similar technique to mark up SVG to
generate multiple images that are then built into movies - it works
like a charm considering how low tech it is.


Saul

[1] http://clojure.github.com/clojure-contrib/strint-api.html
[2] http://www.javaworld.com/javaworld/jw-12-2001/jw-1228-velocity.html
[3] 
http://weblogs.java.net/blog/aberrant/archive/2010/05/25/using-stringtemplate-part-1-introduction-stringtemplate

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