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.