emacs-devel
[Top][All Lists]
Advanced

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

Re: Is this a bug of Emacs-Lisp?


From: Giorgos Keramidas
Subject: Re: Is this a bug of Emacs-Lisp?
Date: Fri, 17 Feb 2006 18:21:37 +0200

On 2006-02-17 13:47, Zhang Wei <address@hidden> wrote:
> (defun dummy () '(1 . 2))
>
> (dummy)
>  => (1 . 2)
>
> (setcdr (dummy) 3)
>
> (dummy)
>  => (1 . 3)
>
> Modify the return value of dummy changed it's defination. Is this
> a bug of Elisp? If it's not. How does this happen?

You are modifying a `literal' cons cell.  It's not mandatory for the
LISP reader to create a new cons cell every time the (dummy) function
runs.

If you really want to create a new cons cell every time (dummy) runs,
you'll have to explicitly do that in the function:

    (defun dummy ()
      (copy-tree '(1 . 2)))
    => dummy

    (setcdr (dummy) 3)
    => 3

    (dummy)
    => '(1 . 2)





reply via email to

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