[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is this a bug of Emacs-Lisp?
From: |
David Kastrup |
Subject: |
Re: Is this a bug of Emacs-Lisp? |
Date: |
Fri, 17 Feb 2006 18:20:33 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
Zhang Wei <address@hidden> writes:
> (defun dummy () '(1 . 2))
>
> (dummy)
> => (1 . 2)
>
> (setcdr (dummy) 3)
>
> (dummy)
> => (1 . 3)
>
> Modify the return value of dummy changed it's defination.
No, it didn't.
> Is this a bug of Elisp? If it's not. How does this happen?
'(1 . 2) is a cons cell. Cons cells are _always_ accessed by
reference, like arrays and strings.
So what is compiled into the function is a reference to a cons cell,
and this reference stays the same. setcdr however changes the cons
cell itself.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
- Is this a bug of Emacs-Lisp?, Zhang Wei, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?,
David Kastrup <=
- Re: Is this a bug of Emacs-Lisp?, Kevin Rodgers, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?, Giorgos Keramidas, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?, Andreas Schwab, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?, Luc Teirlinck, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?, Luc Teirlinck, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?, Alan Mackenzie, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?, Sascha Wilde, 2006/02/17