You can have your cake and eat it too.

I haven't touched this code in years, but there's no reason it shouldn't
still work with the current version of Clojure.

https://github.com/apache/tapestry-5/tree/master/tapestry-clojure

Essentially, you provide an interface and map it to a Clojure namespace.
You get back a instance of that interface that you can invoke methods on,
and under the covers, parameters are boxed as necessary and provided to the
Clojure code.

You could do this kind of thing with reflection, this code builds on top of
some Tapestry infrastructure (from, like, 2012) to generate the bytecode on
the fly.

On Sun, Jun 9, 2019 at 9:25 PM eglue <atdi...@gmail.com> wrote:

> Regarding calling Clojure **from** Java...
>
> I saw a Stuart Halloway tweet responding to someone who'd found this a
> "soul-crushing, miserable experience."
>
> I had a similar miserable experience and figured it was just me, but am
> now suspecting that's not the case. (Happy to be shown the light however.)
>
> Stuart H posted https://github.com/stuarthalloway/clojure-from-java to
> demonstrate the ease of Java consuming Clojure, but I find it far more
> important to be able to *compile* Java against Clojure interfaces not
> invoke it dynamically from Java....because dynamic invocation from Java is
> unwieldy to the point of it being a likely deal breaker for any Java shop.
> Dynamically loading classes and invoking methods.... c'mon, no one's going
> to ask their Java devs to do this.
>
> If Clojure doesn't have a good compile-time consumption story for Java
> consumers, I think that's a loss. (Even if it is just providing better docs
> or archetype/bootstrap examples in this regard.) Because otherwise Java
> code bases around the world could be eaten away by (compiled) Clojure from
> the inside out, giving Java dev teams enough time to be overtaken by the
> miracle that is Clojure.
>
> Inspired by Stuart's example, I was successful in putting together a quick
> build to achieve this ideal: https://github.com/atdixon/clojure-from-java
>
> However, I have a few open questions:
>
> - when I tried to AOT only the public-facing clojure code that I needed to
> compile against, I found out at runtime that this wasn't going to work.
> Dynamic clojure code was loading my same types into DynamicClassLoader and
> when my statically-compiled, root-class-loaded code was getting executed
> the ClassCastExceptions of course were flying. So am I right to think that
> you have to AOT everything in order to do this right?
> - IDE support (for me, Cursive) "works" but is non-ideal; you have to
> manually compile the dependee/Clojure jar, then Cursive will let you
> execute Java code against the manually aot-compiled Clojure code
> - AOT producing generics/generic types doens't seem to be part of any of
> this... is this a lacuna in the Clojure AOT space, are there libs that can
> help here?
>
> This story ^^, if made easier, seems to me would boost Clojure adoption in
> Java/JVM shops.
>
> What am I missing?
>
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/clojure/2fcaf22d-2179-4de0-b25b-70ac1b9db58c%40googlegroups.com
> <https://groups.google.com/d/msgid/clojure/2fcaf22d-2179-4de0-b25b-70ac1b9db58c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Howard M. Lewis Ship

Senior Mobile Developer at Walmart Labs

(971) 678-5210
http://howardlewisship.com
@hlship

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/clojure/CACd-vsPoMnXYRSpoGTLbDscZudBK37cH33kL7hWUVLXkDWB74A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to