pcdro
pcdro

Reputation: 317

Why is nil returned by Clojure functions that don't return a value?

I'm a new student of Clojure and don't get why "nil" is returned in REPL when I call functions that do not return values.

Above an example:

(println "Hello Nil")
nil

What type of evaluation process are made to reach "nil"?

Upvotes: 3

Views: 2035

Answers (1)

Alan Thompson
Alan Thompson

Reputation: 29958

It is a convention of functional languages like Clojure that every function needs to return exactly one value. For functions like println that are intended to perform side effects (like printing to the screen), it is not always clear what the return value could or should be.

In these cases, nil is a placeholder value that means "nothing" or "not applicable".

Upvotes: 12

Related Questions