I saw that Microsoft announced Java support on Azure today at PDC. Does that mean it will be able to run Clojure (and other JVM languages) as well?
in short yes. clojure can directly call java. It would be very nice to get some clojure wrappers to ease the general boiler-plate-ness.
Related
My team and I are developing an application that makes use of Flink.
The data will be processed using a computationally-heavy numerical algorithm.
In order to optimize it as much as possible, I would like to write this algorithm in C/C++ rather than in Java.
The question is: is it possible to use C/C++ code within Flink? Perhaps by wrapping it into a Java library?
I've never tested this case in particular. In general, you can always use native code from Java using JNI, the Java Native Interface.
The idea would be to have a Java facade expose your native code and use these methods in your computation graph defined with Flink in Java (or other JVM languages, like Scala). You would have to make both Java and native libraries available on all involved nodes to make this work. If you have an Hadoop cluster you can leverage YARN to ship files along with your job (docs here, see --yarn-ship CLI option).
I would suggest you test this incrementally, with a very small native function exposed. Also, don't underestimate Java's capabilities in terms of performance: with some well thought programming and leveraging JIT and other runtime optimizations, long running processes can enjoy even better performances than similar native code with unmanaged memory.
Keep in mind that this of course resorting to native code will mean restricting the portability of your code to the platforms for which you'll compile your libraries.
I remember I used to work at a company that couldn't run their JVM software on the OpenJDK JVM. They had to use the Oracle JVM. (Full disclosure: they were writing in groovy/grails.)
But I look at a lot of other JVM applications, and they seem to work fine on both JVMs. The OpenJDK JVM seems to be a solid implementation.
Being a Clojure enthusiast, I want to be able to code for both JVMs.
So, specifically:
What are some common "gotchas" which, if you were targeting one JVM, you would have to be careful about when writing for a different JVM?
Are there any language specific pitfalls, especially when it comes to clojure?
When writing a clojure application, is there any common pitfalls in targeting both JVMs?
I don't know of any significant issues between different JDKs for Clojure. We do matrix test builds on several JDK versions and providers - see http://build.clojure.org/job/clojure-test-matrix/ for the current list.
are there any documentation on clojure built-in java method?
for example, .toUpperCase from java.lang.String and .indexOf from clojure.lang.PersistantVector.
Is there anyway I can find useful java method without looking at the source code?
As others have pointed out, you can get the java.* and javax.* documentation online pretty easily as it is part of core Java.
For the clojure.*, your best reference is the source. Even so, I'd recommend not relying on it since this code should really be considered an implementation detail of Clojure. You have no guarantee that the functionality won't change in future versions of Clojure and break any code that depends on it.
How about the Java API? All of Java's classes and methods are listed there. That covers all of the "clojure built-in java methods".
On the other hand, Clojure's classes are documented in here, Clojure's API. You have to learn to distinguish between Clojure's classes and Java's classes. All packages starting with java.* or javax.* belong to Java and are documented in the first link. The packages starting with clojure.* are from Clojure, you'll find their documentation in the second link.
If the package for the class starts with java or javax then you can look it up in the Java documentation on Oracle's website.
For Clojure implementation classes (where the package name starts with clojure) you are probably stuck with looking at the source code. There is documentation for the intended API (the Clojure language) but not for the Java classes implementing it. You may be able to find some articles (like this one) depending on if what you're looking for is something a blogger has taken an interest in.
Has anybody had any experience accessing the Autocad or Inventor API with Clojure?
If you can access autocad through Java, then you can get to it from Clojure. I found this SO question on that matter. (http://stackoverflow.com/questions/856973/interfacing-autocad-with-java) Basically they've built a JNI bridge to the autocad API. Once you do that then you can access that through Clojure. It sounds like a non-trivial undertaking though to say the least.
I'm pretty old, and the last time I checked (cough 20+ years ago cough), Autocad was extensible via Autolisp. If that's still true, then would you really want to bolt on Clojure? Just curious.
As far as I know, AutoDesk exposes API for their products in .net environment. There is a paralel clojure implementation in Microsoft clr (.net environmet).
https://github.com/richhickey/clojure-clr
I think this would be a better way to aproach Autocad Scripting.
Are there any implementations of Clojure being built for other virtual machines (such as .Net, Python, Ruby, Lua), or is it too closely tied to Java and the JVM? Does it make sense to build a Clojure for other platforms?
There are currently three implementations of Clojure that I know of:
ClojureCLR, an implementation of Clojure for the CLI,
ClojureScript, an implementation of (a subset of (a variant of)) Clojure for ECMAScript and
a Clojure implementation for the Java platform, confusingly also called Clojure.
In fact, the name Clojure was specifically chosen by Rich Hickey because it contained both the letters CLR as well as the letter J.
I've heard rumours of implementations for the Objective-C/Cocoa runtime, LLVM and the Rubinius VM, but I have no idea whether or not those actually exist.
" or is it too closely tied to Java and the JVM?
Does it make sense to build a Clojure for other platforms?"
One of the Clojure design philosophies is embrace the host platform. Clojure on the JVM embraces the JVM and gives direct access to classes, numbers etc. interop is both ways with out glue.
ClojureScript embraces JavaScript(ECMAScript) in exactly the same way, giving direct access to Objects, numbers, etc. the same for the .NET target.
It is tempting, but not always successful, to make 'cross platform' languages that run the exact same source code on multiple platforms. Thus far Clojure has avoided this temptation and strives to remain close to the host.
There exits at least a ClojureCLR project by Rich Hickey himself.
This project is a native implementation of Clojure on the Common Language Runtime (CLR),
the execution engine of Microsoft's .Net Framework.
ClojureCLR is programmed in C# (and Clojure itself) and makes use of Microsoft's
Dynamic Language Runtime (DLR).
I'm not sure that Python and Ruby ports make sense, those are languages with multiple virtual machines / implementations. If you want to have native interop between Clojure and Python or Ruby you could use Jython or JRuby and stay on the JVM.