help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why doesn't nconc change my variable?


From: Pascal J. Bourguignon
Subject: Re: Why doesn't nconc change my variable?
Date: Sun, 05 Oct 2014 03:59:39 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:

> Hi list,
>
> I don't get it.
>
> (setq my-list ())
> (nconc my-list '("wtf"))
>
> and my-list is still nil.
>
> If, OTOH, I do
>
> (setq my-list ())
> (setq my-list (nconc my-list '("wtf")))
>
> my-list is ("wtf").
>
> Why is that so?  I though nconc is supposed to change all its arguments
> but the last one.  Is the latter construct a correct way of adding an
> element at the end of the list?

() is actually read as the symbol nil.
Symbols are symbols, and not cons cells.  
You cannot transform a symbol into a cons cell.
It is impossible for any function to transform nil into a cons cell.

And vice-versa, it is impossible to transform a cons cell into a symbol
such as nil.  This is the reason why you should also use setf when
deleting elements from a list:

   (setf list (delete e list))


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

[Prev in Thread] Current Thread [Next in Thread]