Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is very interesting, but I don't see any section in the docs about JVM interop. I am curious what is the effort needed to use a library written in java (and potentially other jvm languages) in claro.


Great question! This is actually something that will take more work to pull off "right" - but it's definitely planned.

For now, Java code can call into Claro code in a fairly straightforward way. The main hurdles are:

- the namespacing/naming of the Claro code you're calling into is funky because Claro doesn't use Java's "package" namespacing system

- manually constructing non-primitive data to pass to Claro procedures is currently very annoying and, more importantly, unsafe (you could break Claro's type system rules)

In the other direction, Claro's only (current) mechanism for calling into Java directly is restricted to the stdlib's implementation. For example the deque Module[1] exports an `opaque newtype mut Deque<E>` that is actually just a `java.util.ArrayDeque<E>` underneath[2]. The reason this isn't exposed to Claro programs outside the stdlib (yet) is because:

- the type systems are very dissimilar and would need mapping

- Claro doesn't use Exceptions, so you'd have to ensure that any calls into Java code that can throw manually catches and models an error return value[3]

All this said, it's very possible that in the future these limitations can be addressed!

[1] https://docs.clarolang.com/stdlib/deque_module.generated_doc...

[2] https://github.com/JasonSteving99/claro-lang/blob/b5e33ae4ef...

[3] https://github.com/JasonSteving99/claro-lang/blob/b5e33ae4ef...


If the author doesn't read this thread, maybe you can open an issue with this topic. I think other people would be interested in this, so maybe the author prioritises it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: