Do you know any libraries that are written in Clojure but targeted / widely used for Java?
(much bigger than a “library” though)
More of a platform, but interesting to see, thanks!
Yes… I feel like most Clojure libraries would be a bad fit for Java. Hard to imagine how an idiomatic Clojure library can be conveniently used from Java… Perhaps something about managed in-process concurrency, where it can utilize the Clojure concurrency primitives behind the scenes. Immutable data structures and dynamic data transformation (which Clojure is excellent at) are quite foreign to Java.
That’s the point I am wondering about. Currently building a lib that could also be beneficial for Java devs, and I’m wondering about the API or a thin shim layer.
Perhaps expose a number of public static methods
Depends on the arguments though… would it take Objects? Passing in Clojure data structures from Java is a no-go as far as ease-of-use
Or a small wrapper object. In my experience, Java folks are cautious about stuff that they cannot inject 😅
Gotta get that DI fix. 🙂
I would not require objects, most operations use identifiers. Some dynamic data structures, that’s the tricky part. Would not like to expose Map<String, Object>
Apache Storm
Perhaps check if https://clojuredocs.org/clojure.core/bean can be helpful
on your (library) side, to read the objects coming from Java
@vemv Apache Storm is unfortunately moving from Cloure to Java 😞
@raspasov Thanks, this will come in handy
If you want to expose the library to Java developers it would be helpful for them if you define interfaces, even in Java files (although you may be able to use protocols for that) for them to work against. Then you implement those interfaces however you like on your end (reify, deftype, defrecord) while leaving it open for others
I did an example of that here https://github.com/puredanger/clojure-from-java
@javahippie #clara was developed by a clojure sub-team inside a java application Also, #storm was developed in clojure but it's main API was in java (now storm V2 was rewritten in java)
Windows huh?
Huh.. Does this mean windows is immutable?
Oh, you may not be able to delete it, but maybe you can edit it
It's extremely dangerous to delete existing files. It's sure to cause data loss.
Generally unless the project is large, I can't imagine it happening
clojure does not provide all the mechanisms you would need to provide easy/comfortable/idiomatic access from java
at least without significant wrapping overhead
@ben.sless That sounds like a good approach, thank you!
@alexmiller Will definitely look into that!
@souenzzo thanks for the pointers to clara, was planning to look into it, anyways
@emccue What don’t you see happening, adoption of a Clojure library in Java, or making it technically possible?
well, just justifying the overhead
as in
you can make a java interface in clojure, but it wont have generic types
you can return maps to java, but java users expect objects with named properties
Sure, you’d need to wrap all of that (if it’s not dynamic data structures)
i guess it would matter a lot what library you are writing and where the bulk of the logic goes
but its definitely not the same situation as with scala or kotlin where you can mostly just write it like normal and interop is relatively straightforward
I just can't think of a good strawman library where writing it in clojure would be the right call
Returning records won't satisfy the need for objects with named properties?
nope
lets say we had this and aot compiled it
(defrecord SimpleResult [stuff])
Java would see Object stuff()
what you want is List<String> stuff()
- you can get to List stuff()
with clojure typehints but that isn't great either