Lisp: Is there a difference between 'nil and nil?

AND

(not 'nil)

      

and

(not nil)

      

rate T

, so is there a difference between 'nil

and nil

? How about ''nil

? If ''nil

evaluated as 'nil

, shouldn't the ''nil

value be evaluated nil

?

+3


source to share


3 answers


(quote <anything>)

means literally <anything>

. The designation '<anything>

means (quote <anything>)

, and no matter what <anything>

, it just returns without evaluation.

It also nil

evaluates itself.

Other objects quoted as literals also evaluate themselves: certain characters and all non-character atoms are.

What is the difference between '2

and 2

? They both rate up 2

!

Also, what is the difference between '"abc"

and "abc"

and between :foo

and ':foo

?



The difference is what '2

is form (quote 2)

versus what 2

is simple 2

. They rate the same thing, but not the same thing.

For Lisp evaluation, means that the base point is treated as the source code of the expression. Two expressions can have the same meaning, but be made from different data. For example, 4

, (+ 2 2)

and (* 2 2)

.

Tell me what's the difference between 4

and (+ 2 2)

?

If 4

and (+ 2 2)

both produce 4, then why '4

create 4

, but '(+ 2 2)

create (+ 2 2)

?

The quote means "give me this piece of code as a binding, not the value it stands for."

+8


source


When you evaluate NIL

, you get the value of a variable named NIL , and when you evaluate 'NIL

, you get a character named NIL. However, these two things are defined by the specification as the same object. See Hyperspec for Zero :

nil n. an object that is both a symbol with a name "NIL"

in a package COMMON-LISP

, an empty list, a boolean (or generic boolean) representing false, and an empty type name.

You can check it yourself:



(eq NIL 'NIL) ==> T

      

However, the equivalence ceases. ''NIL

matches the list (quote NIL)

.

+6


source


It makes no difference if you only consider the result of the evaluation, i.e.

nil

      

and

'nil

      

evaluate the same value (namely, nil

). However, there is a true difference in the reader's attitude as

nil  ===> nil

      

then

'nil ===> (quote nil)

      

This is interesting especially if you have nested forms like

((nil) 'nil)

      

which reads like

((nil) (quote nil))

      

+1


source







All Articles