On Oct 29, 4:50 pm, vanallan <vanal...@gmail.com> wrote:
> Ok thanks for the answer :)
>
> I have now began to implement the Java parts. The data that is going
> to be processed in Clojure is mapped to clojure structs, but I now
> have another question. How should I update the values in the structs?
> Since functions are going to run in parallel and a function may need
> the updated value from another function I though that I should put the
> struct members that is going to be updated in refs or maybe atoms. Is
> this a good way or how should I manage the updated values in structs?

This, I think depends on your use case. If the parallel functions are
in Clojure, then atoms and refs may help. If some functions are in
Java and some in Clojure, and both sets of functions work in parallel
to update commonly stored data then you should stick to concurrent
Java collections (java.util.concurrent.*). But again, this depends on
the use case.

I think as long as the Java consumer class is ready to accept
java.util.Map you can simply return a modified struct and it will be
understood. But there is a pitfall to watch for -- the struct you
return from Clojure will be immutable, so none of put(), remove() etc
will work in Java then. When you are integrating Java with Clojure you
should remember this aspect, and probably you will benefit
tremendously if you code the Java part in a functional style, for
example:

1. Go Immutable -- use the "final" keyword a lot (ensures at least
immutable references)

2. Go Functional -- pass objects and anonymous functions (Strategy and
Mediator patterns may help)

3. Don't presume data structures to be mutable


HTH

Regards,
Shantanu
--~--~---------~--~----~------------~-------~--~----~
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