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: Mon, 09 Nov 2009 22:04:41 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

pjb@informatimago.com (Pascal J. Bourguignon) writes:

> Francis Moreau <francis.moro@gmail.com> writes:
>
>> pjb@informatimago.com (Pascal J. Bourguignon) writes:
>>
>>> Francis Moreau <francis.moro@gmail.com> writes:
>>>>>> 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 ?
>>>
>>> Yes.
>>>
>>
>> Sorry for being blind but I can't find the revelant section.
>>
>> Could you give me a pointer ?
>
> Well, there are several places where it's covered, but here is one
> where it's explicitely explained:
>
>
> (info "(elisp)Rearrangement")
>
>
>  -- Function: nconc &rest lists
>
>      [...]
>
>      A common pitfall is to use a quoted constant list as a non-last
>      argument to `nconc'.  If you do this, your program will change
>      each time you run it!  Here is what happens:
>
>           (defun add-foo (x)            ; We want this function to add
>             (nconc '(foo) x))           ;   `foo' to the front of its arg.
>
>           (symbol-function 'add-foo)
>                => (lambda (x) (nconc (quote (foo)) x))
>
>           (setq xx (add-foo '(1 2)))    ; It seems to work.
>                => (foo 1 2)
>           (setq xy (add-foo '(3 4)))    ; What happened?
>                => (foo 1 2 3 4)
>           (eq xx xy)
>                => t
>
>           (symbol-function 'add-foo)
>                => (lambda (x) (nconc (quote (foo 1 2 3 4) x)))

ok that tells: "don't do that !" but it doesn't tell why not...

>
> Of course, it could be infered from:
> C-h f quote RET
> or:
> (info "(elisp)Quoting")

There's nothing here about a cons built by the Lisp Reader.

Thanks
-- 
Francis


reply via email to

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