From: ··········@bbs.ee.ncu.edu.tw
Subject: Behavior of NIL
Date: 
Message-ID: <1130608147.178370.49360@g49g2000cwa.googlegroups.com>
For investigation of the NIL , I wrote the following codes and
these codes run well in the ARC xlisp-stat.

(if nil (format t " ~a ~%" 123 ))
NIL
> (if 'nil (format t " ~a ~%" 123 ))
NIL
> (if ''nil (format t " ~a ~%" 123 ))
 123
NIL

As you can see , 'nil = nil  , and ''nil <> 'nil .
This suprises me because if 'nil =nil , why not ''nil = '('nil)='nil
(substitution as in algebra)?

From: Joe Marshall
Subject: Re: Behavior of NIL
Date: 
Message-ID: <64rg19f5.fsf@alum.mit.edu>
··········@bbs.ee.ncu.edu.tw writes:

> For investigation of the NIL , I wrote the following codes and
> these codes run well in the ARC xlisp-stat.

You are actually investigating the behavior of QUOTE.

> (if nil (format t " ~a ~%" 123 ))
> NIL

In this example, the identifier NIL is used.  The identifier NIL is a
constant that has the value of the symbol named "NIL".  If I wrote
this:
  (defconstant foobar 'nil)

Then the identifier foobar would also be a constant with the value of
the symbol named "NIL".

>> (if 'nil (format t " ~a ~%" 123 ))
> NIL

By quoting the form, you instruct the computer to not use the
identifier NIL as a variable reference, but rather as a literal
symbol.  But the identifier NIL refers to the literal symbol NIL, so
there should be no change in behavior.

>> (if ''nil (format t " ~a ~%" 123 ))
>  123
> NIL

In this example, you instruct the computer not to use the identifier
NIL, nor even the literal symbol NIL, but instead to use the literal
list (QUOTE NIL).  This is a list of two elements and not a symbol.
In particular, it is not the symbol NIL, so the conditional evaluates
to true.

> As you can see , 'nil = nil  , and ''nil <> 'nil .
> This suprises me because if 'nil =nil , why not ''nil = '('nil)='nil
> (substitution as in algebra)?

That's an incorrect argument.

(defconstant foobar 'xyzzy)

(eq foobar 'xyzzy) => T    ;; foobar is bound to the symbol xyzzy

(eq 'foobar ''xyzzy) => NIL  ;; the symbol foobar is not the list (quote xyzzy)

Do you see why this example works the way it does?

Now consider this one:

(defconstant quux 'quux)

(eq quux 'quux) => T  ;; quux is bound to the symbol quux

(eq 'quux ''quux) => NIL ;; the symbol quux is not the list (quote quux)
From: Luís Oliveira
Subject: Re: Behavior of NIL
Date: 
Message-ID: <m2u0f0gq0y.fsf@pomajxego.local>
··········@bbs.ee.ncu.edu.tw writes:
> (if nil (format t " ~a ~%" 123 ))
> NIL

(eval nil) => nil  ; false condition.


>> (if 'nil (format t " ~a ~%" 123 ))
> NIL

(eval 'nil) => nil  ; false condition.


>> (if ''nil (format t " ~a ~%" 123 ))
>  123
> NIL

(eval ''nil) => (quote nil)  ; true condition.


-- 
Luís Oliveira
luismbo (@) gmail (.) com
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt
From: Luís Oliveira
Subject: Re: Behavior of NIL
Date: 
Message-ID: <m2pspogp6o.fsf@pomajxego.local>
·············@deadspam.com (Luís Oliveira) writes:
> (eval nil) => nil  ; false condition.
> (eval 'nil) => nil  ; false condition.
> (eval ''nil) => (quote nil)  ; true condition.

Erm, oops. Those NILs passed to EVAL should have an extra
quote... Better read the other explanations instead. :-)

-- 
Luís Oliveira
luismbo (@) gmail (.) com
Equipa Portuguesa do Translation Project
http://www.iro.umontreal.ca/translation/registry.cgi?team=pt
From: Pascal Costanza
Subject: Re: Behavior of NIL
Date: 
Message-ID: <3shrudFo797vU1@individual.net>
··········@bbs.ee.ncu.edu.tw wrote:
> For investigation of the NIL , I wrote the following codes and
> these codes run well in the ARC xlisp-stat.
> 
> (if nil (format t " ~a ~%" 123 ))
> NIL
> 
>>(if 'nil (format t " ~a ~%" 123 ))
> 
> NIL
> 
>>(if ''nil (format t " ~a ~%" 123 ))
> 
>  123
> NIL
> 
> As you can see , 'nil = nil  , and ''nil <> 'nil .
> This suprises me because if 'nil =nil , why not ''nil = '('nil)='nil
> (substitution as in algebra)?

The ' syntax is just an abbreviation for quote. So 'nil is (quote nil). 
It is a good idea to use quote instead of ' in the beginning, because 
this makes a lot of things clearer.

nil is one of the self-evaluating forms in Lisp. Self-evaluating means 
that if you type the form in the Lisp listener, you will get exactly the 
same thing back. For example, this is true for numbers and strings, but 
also for the boolean values nil and t.

quote is an operator that takes its parameter and returns it without 
evaluating it. In the following example, the variable x is bound to a value:

(let ((x 42))
   (list x (quote x)))

The list that is returned by that expression will consist of the entries 
42 and x. The second entry will be x because (quote x) says not to 
evaluate x but to return it as is.

This is why (quote nil) returns nil (without evaluating it), but because 
the value of nil is nil because it is self-evaluating, this finally 
means that (quote nil) and nil both return the same value nil.

Now, for (quote (quote nil)) you can blindly apply what I have described 
above: quote returns its parameter without evaluating it, so (quote 
(quote nil)) will return (quote nil) which is clearly not the same value 
that is returned by both (quote nil) and nil.

In order to better understand this, it might be a good idea to type in 
(list (quote (quote nil)) (quote nil) nil) in your Lisp listener and try 
to understand the result of that expression.

I hope this helps.


Pascal

-- 
My website: http://p-cos.net
Closer to MOP & ContextL:
http://common-lisp.net/project/closer/
From: Kaz Kylheku
Subject: Re: Behavior of NIL
Date: 
Message-ID: <1130721079.461349.160180@z14g2000cwz.googlegroups.com>
··········@bbs.ee.ncu.edu.tw wrote:
> As you can see , 'nil = nil  , and ''nil <> 'nil .

> This suprises me because if 'nil =nil , why not ''nil = '('nil)='nil
> (substitution as in algebra)?

Because there is nothing like the quote operator in ordinary algebra!!!

In Lisp, you can quote an expression, and then it becomes data.

In ordinary algebra, you cannot quote a formula and turn it into data
(i.e. into an algebraic quantity, a number).

There is a kind of quoting you can do in algebra, which is the basis
for some very important results in number theory and logic.

A mathematical formula can be turned into a number by means of Goedel
numbering named after the mathematician and logician Kurt Goedel: you
take the ``source code'' of the formula---the characters that make it
up---and assign them codes, similar in concept to ASCII or UNICODE.
These codes make up a string that represents the formula: you catenate
the numbers together to make one big number. That number is than the
Goedel number of the formula (under your particular choice of notation
and numbering).

Let's use the notation #F to mean "the Goedel number of formula F".

Now then, suppose you can find a very particular formula that evaluates
to a constant integer. It contains no free variables like X or anything
of the sort. It's just an expression like 2 + 2.  This particular
formula has the curious property that the value it produces is its own
Godel number! Let's call that formula G. You could then write down
this:

   #G = G

The left hand says ``the Godel number of G'', and the right hand says
``the value of formula G''. The equation says they are equal: The Godel
number of G is the same as evaluating G.

Now as you can see, the ``algebraic substitution'' won't work, namely:

   ##G <> #G

On the left hand side, the ##G means "the Goedel number of the formula
#G", and on the right hand side, you have "the Goedel number of G,
which is G".

Algebraic substitution does not work, because the # operator treats the
following formula as characters which are to be encoded numerically,
and not as the mathematical formula that it represents.

Only for very special formulas is it true that #G = G. G is such a
formula. But #G is not such a formula!!!

The Goedel number of the formula G is equal to G, but the Goedel number
of the formula #G is not equal to #G (which is G!!!). Why? Because #G
has an extra symbol in the front, whose character code must be factored
into the Goedel number, and that changes its value. Suppose that the
Goedel number of G is  12345 .. (lots of digits) .. 687. This happens
to be the value of G also. Now suppose that the code for the #
character is 999.  The Goedel number of #G is therefore 99912345 ...
687. That extra 999 is stuck on the front, so this number is not G!!!
Because of this problem, #G does not have the magic property that its
Goedel number is #G.

Similarly, in Lisp, the relation (eq 'x x) holds only for special kinds
of X, namely symbols that evaluate to themselves, such as nil. If you
substitute NIL for X, the result is T.  If you substitute (QUOTE NIL)
for X, it's no longer T. (quote nil) does not have that special
property that it evaluates to its own image, and so (quote (quote
nil)), which does evaluate to the image of (quote nil), is not the same
as (quote nil), which does NOT evaluate to the image of (quote nil).