nil

special symbolsince v0.0-1853 in clojure in ednEdit

nil is a representation of nothing. Its underlying representation is JavaScript's null, and is equal to JavaScript's undefined when compared.


Details:

It is common for operations to safely handle nil without causing exceptions.

Expressions evaluate to nil if there is no value to return.


Examples:

nil
;;=> nil

nil can sometimes mean "not found":

(:foo {})
;;=> nil

nil can also mean that the operation didn't make sense:

(:foo nil)
;;=> nil

Reader code @ tools.reader:src/main/clojure/clojure/tools/reader.clj
(defn- read-symbol
  [rdr initch]
  (let [[line column] (starting-line-col-info rdr)]
    (when-let [token (read-token rdr :symbol initch)]
      (case token

        ;; special symbols
        "nil" nil
        "true" true
        "false" false
        "/" '/

        (or (when-let [p (parse-symbol token)]
              (with-meta (symbol (p 0) (p 1))
                (when line
                  (merge
                   (when-let [file (get-file-name rdr)]
                     {:file file})
                   (let [[end-line end-column] (ending-line-col-info rdr)]
                     {:line line
                      :column column
                      :end-line end-line
                      :end-column end-column})))))
            (err/throw-invalid rdr :symbol token))))))