[Top][All Lists]

[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 19:50:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Marcin Borkowski <> writes:

> On 2014-10-05, at 03:59, Pascal J. Bourguignon wrote:
>> Marcin Borkowski <> writes:
>>> Hi list,
>>> I don't get it.
>> () 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))
> I still don't understand.  What if I used (list) to generate an empty
> list instead of () or nil?  The results seem to be still the same.

The function list returns nil or a cons.

When it's given no argument, like in (list), it returns nil.

When it's given N arguments, with N>=1, then it returns N new conses,
cdr-linked, with each argument in order stored in the car slots.

So if you used (list) it would make no difference, you'd have to store
the result of delete or of nconc to the variable:

    (setf list (delete 42 (list)))

    (let ((list (list)))
       (setf list (nconc list (list 42)))

__Pascal Bourguignon__       
“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]