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

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

Re: Basic questions about elisp


From: Francis Moreau
Subject: Re: Basic questions about elisp
Date: Fri, 06 Nov 2009 21:53:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

David Kastrup <address@hidden> writes:

> Francis Moreau <address@hidden> writes:

[...]

>>
>> Basic principle of _elisp_ programming, I asssume...
>
> Of Lisp programming.
>
>>> Only ever use destructive list operators like nconc on lists that
>>> have been consed together _entirely_ under your control.
>>>
>>> In this particular case, the cons '(2) has been consed together under
>>> control of the Lisp reader.  The second time this code gets executed,
>>> the cons is destroyed.
>>
>> eh ?
>
> Did you try my example?

nope I was a bit confused by what you wrote and your example was using
'dotimes'.

>
>
>> When I wrote '(2), I suppose the elisp interpreter to create a new
>> list.
>
> It does so, but at read time.  Not execution time.
>

Ah ok I see what you mean now.

That's a pretty important point, is this part covered by the elisp info ?

Actually the same stands for the implementation of the list, where
nconc, length... are O(n). I wouldn't have thought that lists are really
implemented by the car & cdr thing only.

>
> And
>
> (let ((lst (list 1 2 3)))
>    (dolist (elt lst)
>      (when (< elt 3)
>        (nconc lst '(4))))
>    lst)
>
> just crashes.

OK.

-- 
Francis


reply via email to

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