From the Clojure source code, lang/LispReader.java
:
static private Object interpretToken(String s) throws Exception{
if(s.equals("nil"))
{
return null;
}
From lang/RT.java
:
static public void print(Object x, Writer w) throws Exception{
{
...
if(x == null)
w.write("nil");
So nil
is Clojure's representation for the underlying platform's null
. nil
shows up nowhere else in the Java source for Clojure. The only difference between nil
and null
is that one is Clojure and the other is Java, but they're essentially aliases, converted back and forth seamlessly as needed by the reader and printer when going from Clojure to Java to Clojure.
Yeah, nil
can cause NullPointerException
s. Try calling any Java method on nil
, you'll get an NPE, e.g.
(.tostring nil)
The Clojure source code is pretty easy to read when it comes to things like this, give it a look.
I think either language will be fast enough for you. When comparing Python and Java, it seems a bit unreasonable to blame the language for the speed difference. Java is compiled JIT (except on mobile devices*) whereas Python is interpreted. Just because both use a bytecode does not mean the implementations will have even remotely comparable performance. But both Scala and Clojure are JVM languages so they should have similar performance.
Scala has a few implementation advantages over Clojure and I would expect somewhat higher performance. Although Scala's static typing would normally translate into a speed advantage over Clojure's duck typing, Clojure does support type hinting which can speed up code considerably. Possibly, ordinary Scala is faster than ordinary Clojure, but you only need to optimize the bottlenecks. Most of a program's run time is generated by a small amount of the actual code.
Regarding interop w/ Java, Scala is closer to Java but I'm sure both languages interoperate well. In Programming Clojure Stuart Halloway writes: "[you can access] anything you could reach from Java code.".
And since Scala author Martin Odersky wrote Sun's Java compiler, I kinda think no balls have been dropped on the Scala side, either. :-)
You would be hard-pressed to pick two better languages, though I like Ruby also. Why are you worried about which one to try? Why not try them both? Scala is more likely to be "the next Java", while it's hard to imagine that Lisp will finally take off after not doing so for over 50 years. But it's clear that Lisp is on its own unique level of abstraction, and Clojure is fairly simple, so Scala + Clojure won't be that much harder than just (the rather complex) Scala and I'm sure you will be glad you did it.
And for that matter they interoperate...
* dalvik (android's JVM) got a JIT compiler in 2.2 version in 2010
Best Answer
After Clojure 1.6 you can use
some?
:This is useful, eg, as a predicate: