On Fri, 2012-06-29 at 23:56 +0200, Jacek Laskowski wrote:
> They're fine with the job, but they do everything in Java. I thought
> I'd introduce Clojure as a functional language to solve some problems
> that are functional in nature, like processing XML files. I said I'd
> show you how to do it different (well, I used the word "better").

If you want to do this, a smaller surface area of interaction with Java
is safer for a starting approach.  Solve a complex problem that would be
pointlessly expensive/tedious to reimplement in Java, but remains
loosely attached to the rest of the system.

I'll assume you considered this and went with your initial plan anyway.
Notwithstanding any issues with that,

> The job of the XML parser module is to expose attributes with getX()
> method-like style to other Java modules. There's a XML file of which
> attributes should be available with getAnAttribute() methods.

In Javanese, such methods must be known to javac, that is *at compile
time*, to be called directly.  Scala and C# (and anything with a less
fancy compiler) offer native solutions for this, but none such is
generally available for Java.

So you must provide every such possible method as a concrete Java method
without having read any XML yet.  If you want to generate those methods,
you will certainly have a spectacularly easier time doing so in Clojure
rather than Java.

However, if you can't constrain the set of methods in any way, you
should seek a problem redefinition.

> I can read a XML file and process its elements, but don't know how to
> expose them with getters. Should I create a Java class with necessary
> getters and execute Clojure functions so to make the Java class a
> wrapper

You can just use the Java class you can get from Clojure.

> or use AOT to generate getters off a Clojure namespace,
> possibly a Clojure record?

Records aren't of much interest to your problem.

> How would you approach the task?

This has been done before already (I'm pretty sure, anyway), so I would
probably use whatever already exists.  Notwithstanding that:

Parse a schema file, maybe RELAX NG, that describes the XML format to be
read, generating simple sum and product Java types according to the
hierarchy of types implied by the schema.

If you have less time and are willing to produce something less happy
for Java, take a list of all possible whatevers and generate a big class
with all of the getters.  Maybe you could derive that list from an XML
file of some kind.

-- 
Stephen Compall
^aCollection allSatisfy: [:each|aCondition]: less is better

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