[ACCEPTED]-What is the exact difference between NULL and NIL in Common Lisp?-null

Accepted answer
Score: 10

NIL is a symbol. It's also written as (). The 13 output of type-of is not necessarily useful here. the 12 HyperSpec says about type-of:

Returns a type specifier, typespec, for 11 a type that has the object as an element.

But 10 given type hierarchies, as well as a universal 9 type (everything is of type t), the output 8 of type-of can be unhelpful. What's more 7 useful here, if you want to know whether 6 something has a particular type is typep. Using 5 typep, we can see that, regardless of what 4 type-of tells us, that nil is a boolean, is 3 a symbol, and is a list, and a null. On 2 the other hand, t is a symbol, a boolean, not 1 a list, and not a null.

CL-USER> (type-of nil)
CL-USER> (type-of t)
CL-USER> (typep nil 'boolean)   ; both are booleans
CL-USER> (typep t 'boolean)
CL-USER> (typep nil 'symbol)    ; both are symbols
CL-USER> (typep t 'symbol)
CL-USER> (typep nil 'list)      ; only nil is a list
CL-USER> (typep t 'list)
CL-USER> (typep nil 'null)      ; only nil is a null
CL-USER> (typep t 'null)
Score: 5

You might think it's strange that T is a 15 boolean while NIL isn't. The reason is that 14 NIL has several hats. It's the empty list, it's 13 the symbol NIL, it's boolean false. So it 12 sometimes occurs in contexts not appropriate 11 for a boolean-typed value, hence the type 10 boolean is not appropriate for it from a 9 type-safety perspective. Somewhat similarly, in 8 Scheme boolean false is different from the 7 empty list.

NULL is given as the type of NIL.

NIL is 6 the symbol that represents NULL in Common 5 Lisp. It is also the representation of the 4 empty list (). #'NULL is the function that checks 3 if a variable is NULL (ie. eq NIL).

You may define 2 NULL if you want to use NULL instead of 1 NIL. (This is probably a terrible idea in practice.)

(defconstant null nil)
(type-of NULL) ; ==> NULL
NULL           ; ==> NIL
(eq NULL NIL)  ; ==> T
Score: 3

The exact difference is that NULL is a type 5 in your context, while NIL is a symbol.

NULL 4 is the type containing only the symbol NIL.

NIL 3 as a type is the empty type (there is no 2 object that has type NIL):

NIL as an object 1 is the symbol representing various "not"-things.

Score: 1

So NULL is not a defined symbol as "BASIC-STRING-6" is 6 not one either.

NULL is a symbol. It has no value. The 5 symbol NULL is the name of a type NULL and the function 4 NULL. NULL as a type has one element: NIL.

NIL is a symbol 3 and NIL is its value. Thus NIL is a constant with 2 itself as the value. NIL is also a type, the 1 empty type with no object.

More Related questions