clojureidioms

Why Clojure idiom prefer to return nil instead of empty list like Scheme?


From a comment on another question, someone is saying that Clojure idiom prefers to return nil rather than an empty list like in Scheme. Why is that?

Like,

(when (seq lat) ...)

instead of

  (if (empty? lat)  
    '() ...)

Solution

  • I can think of a few reasons:

    Note that there are still some functions in Clojure that do return an empty list. An example is rest:

    (rest [1])
    => ()
    

    This question on rest vs. next goes into some detail of why this is.....