(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.
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.
nil is equivalent to an empty list.
CL-USER> (if (list ) 'print-true 'print-false)
; prints PRINT-FALSE
CL-USER> (if (list nil) 'print-true 'print-false)
; prints PRINT-TRUE
'(nil) is equiv to (list nil) which is different from an empty list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With