Search code examples
lispclisp

Lisp: Why and how does '(nil nil) evaluate to true?


(if '(nil nil)
    'print-true
    'print-false)

(if '(nil)
    'print-true
    'print-false)

In the code above, why does the Lisp interpreter always evaluate these forms to true (print-true). I thought nil represented false in Common Lisp.

I am using GNU CLISP.


Solution

  • nil is false. Anything else is true. '(nil) is a list with one element, namely nil. '(nil nil) is a list with two elements, namely nil and nil. Neither of these expressions is the same as nil by itself, so if sees it as true.