Using listp to test for list, but (listp nil) returns true

On GNU Clisp 2.49, (listp nil) returns true. Could someone explain? Searching found this question with an answer that indicated that the expression should be returning NIL.

2

1 Answer

In Common Lisp listp returns T for a list. nil is the empty list, so (listp nil) is T. NIL can also be written as ().

CL-USER 38 > (eq (read-from-string "()") (read-from-string "NIL"))
T

In Common Lisp nil has multiple purposes: the symbol named NIL in the COMMON-LISP package, the empty list, the boolean (or generalized boolean) representing false, and the name of the empty type.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like