[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Is this a bug of Emacs-Lisp?
From: |
Kevin Rodgers |
Subject: |
Re: Is this a bug of Emacs-Lisp? |
Date: |
Fri, 17 Feb 2006 12:29:15 -0700 |
User-agent: |
Mozilla Thunderbird 0.9 (X11/20041105) |
Zhang Wei 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?
It is not a bug.
After the defun, (symbol-function 'dummy) =>
(lambda nil (quote (1 . 2)))
That is, the function binding of the symbol dummy is a list of 3 elements:
lambda, nil, and (quote (1 . 2))
That last element is the form that is evaluated to produce the result,
which itself is a list of 2 elements: quote and (1 . 2)
Evaluating (quote x) returns x, which in this case is the (1 . 2) cons
cell. It is not a copy of x, it is x itself, which in this case is a
member of the function binding's sublist.
setcdr is a destructive operation that modifies that object, and by
side-effect, the function definition.
You can even write a self-modifiying function, by having dummy call
setcdr (or any destructive function) on its own function binding.
--
Kevin Rodgers
- Is this a bug of Emacs-Lisp?, Zhang Wei, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?, David Kastrup, 2006/02/17
- Re: Is this a bug of Emacs-Lisp?,
Kevin Rodgers <=
- 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
- Re: Is this a bug of Emacs-Lisp?, Richard M. Stallman, 2006/02/18