Please forgive the term "Java Complete" because I don't know the proper term for this.
I learned that Jython does not support 100% of Java programs. Specifically, one counterexample is that Jython does not support Java Annotations: Jython; translating Java annotations. You cannot take a Java program with annotations and use Jython to re-create the same program in (J)Python.
Is Clojure "Java complete"? As in, literally any program written in Java can be written in Clojure? Or are there things you can do in Java that you cannot in Clojure?
Related
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.
I have a strange request. We're in a position where we need to run a clojure based service in between our python3.3 worker and a database. I'm looking into different ways to interface between python and clojure for this reason. I looked at Thrift, but unfortunately it's doesn't have python3 support yet. 0mq also looked interesting but I'm worried about the req/req pattern blocking the python3 threads (there will be multiple threads on multiple processes needing to use this proxy service).
Are there any other existing libraries in existence that could help me out here? At the end of the day I could write my own service from scratch using aleph and raw sockets, but I feel like that would be re-inventing the wheel too much.
Clojure means JVM. Most languages running on the JVM allow "calling Java" and be "called by Java" which basically means anything else on the JVM. I've never done it, but you can probably call Clojure from Jython. Now Jython doesn't support the Python 3 language, but it does support Pyro.
It's a bit far-fetched but you could try:
JVM
Python-VM Jython Clojure
( Your app -> Pyro ) --> ( Pyro -> Proxy -> Your app )
Arguments of the RMI must probably be translated to Java primitives & Java strings. It might also require some ClassLoader-Voodoo.
I am using ZeroMQ in Python in production quite happily so far; there is Clojure support as well, which I have not really used yet -- it requires native libraries which can be a bit inconvenient. I am going with your ZeroMQ reference even though it's not a full RPC mechanism because often RPC problems can be broken down fairly simply as operations on one or more message queues.
Meanwhile, there is also clojure-py, which would allow you to have your Python and eat your Clojure too. It is still quite young and not without rough edges but most of the core functionality is in place.
Finally, there is always XML-RPC for which both Clojure and Python have libraries, if you just want something simple to glue your Python and Clojure together.
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.
I have started building a system with clojure, mainly because I need to use Java libraries. My main problem with Clojure is lack of proper IDE support (getting it to work well with Emacs on Windows was not trivial). I was wondering what difficulties other people have had.
Lack of "user friendly" stacktraces (coming from Haskell, it felt like a giant step back), but you get used to it eventually and learn to work your way from slime/swank.
Still having nightmare about the days when we didn't have leiningen (classpath mess, start scripts, dependency "management" hell).
It improved a lot and is improving every release it seems.
getting bitten by the "lazy bug".
(with-open [file (writer name)]
(map #(.write file (process %)) (get-data)))
and "the lazy bug" makes your file empty!
ps: the answer is dorun
An idea: if you are working in a Java environment then you might consider sticking with your Java IDE and use a Clojure plugin rather than going with Emacs etc.
For example, my setup works beautifully with:
Eclipse 3.6.1
Counterclockwise plugin for Clojure 0.2.0 RC1 (http://code.google.com/p/counterclockwise/)
Clojure 1.2 libraries (either on the eclipse build path, or automatically imported using Maven)
Interactive development using the REPL provided with Counterclockwise (nREPL)
Since I need to use a lot of Java along with my Clojure code (often in the same project!), this setup makes much more sense than wrestling with a whole new set of tools.
My problems so far:
It wasn't too easy to get EMACS/SLIME with Common Lisp AND Clojure.
Clojure 1.2.0 stacktraces are a mess so far. It's often so hard to get it what went wrong.
The debugging experience is not very nice. Tried JSWAT and Counterclockwise, but not really happy with it.
Changing my mindset from imperative to functional programming.
It got better after I read a book on lisp programming.
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.