* Strange incf behavior in Emacs 22. Intentional?
@ 2007-06-28 12:41 spamfilteraccount
2007-06-28 12:46 ` Thien-Thi Nguyen
` (3 more replies)
0 siblings, 4 replies; 11+ messages in thread
From: spamfilteraccount @ 2007-06-28 12:41 UTC (permalink / raw)
To: help-gnu-emacs
Here are two functions:
(defun testfun1 ()
(interactive)
(setq a '(0 0))
(print a))
(defun testfun2 ()
(interactive)
(incf (car a))
(print a))
I call the first one, a is (0 0).
I call the second one, a is (1 0).
I call the second one, a is (2 0).
I call the first one, a is (2 0).
"a" won't get the value (0 0) again until I redefine testfun1.
I suspect it is caused be some kind of internal optimization. Is it
intentional? It cost me a great deal of head scratching to find out
why my program doesn't work.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
2007-06-28 12:41 Strange incf behavior in Emacs 22. Intentional? spamfilteraccount
@ 2007-06-28 12:46 ` Thien-Thi Nguyen
2007-06-28 13:51 ` Lennart Borgman (gmail)
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Thien-Thi Nguyen @ 2007-06-28 12:46 UTC (permalink / raw)
To: help-gnu-emacs
() "spamfilteraccount@gmail.com" <spamfilteraccount@gmail.com>
() Thu, 28 Jun 2007 05:41:31 -0700
why my program doesn't work.
expression:
'(0 0)
differs from expression:
(list 0 0)
but how/why?
thi
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
2007-06-28 12:41 Strange incf behavior in Emacs 22. Intentional? spamfilteraccount
2007-06-28 12:46 ` Thien-Thi Nguyen
@ 2007-06-28 13:51 ` Lennart Borgman (gmail)
2007-06-28 13:54 ` Juanma Barranquero
[not found] ` <mailman.2737.1183038693.32220.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2007-06-28 13:51 UTC (permalink / raw)
Cc: help-gnu-emacs
spamfilteraccount@gmail.com wrote:
> Here are two functions:
>
> (defun testfun1 ()
> (interactive)
> (setq a '(0 0))
> (print a))
>
> (defun testfun2 ()
> (interactive)
> (incf (car a))
> (print a))
>
>
> I call the first one, a is (0 0).
> I call the second one, a is (1 0).
> I call the second one, a is (2 0).
> I call the first one, a is (2 0).
>
> "a" won't get the value (0 0) again until I redefine testfun1.
>
> I suspect it is caused be some kind of internal optimization. Is it
> intentional? It cost me a great deal of head scratching to find out
> why my program doesn't work.
Are you using Emacs 22? Could you then please file a bug report?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
2007-06-28 12:41 Strange incf behavior in Emacs 22. Intentional? spamfilteraccount
2007-06-28 12:46 ` Thien-Thi Nguyen
2007-06-28 13:51 ` Lennart Borgman (gmail)
@ 2007-06-28 13:54 ` Juanma Barranquero
[not found] ` <mailman.2737.1183038693.32220.help-gnu-emacs@gnu.org>
3 siblings, 0 replies; 11+ messages in thread
From: Juanma Barranquero @ 2007-06-28 13:54 UTC (permalink / raw)
To: spamfilteraccount@gmail.com; +Cc: help-gnu-emacs
On 6/28/07, spamfilteraccount@gmail.com
> (defun testfun1 ()
> (interactive)
> (setq a '(0 0))
> (print a))
The expresion '(0 0) builds a list when you're defining testfun1. That
list is being modified by testfun2().
If you use
(setq a (list 0 0))
you build a new list every time that testfun1 is executed.
Take a look at the Emacs Lisp Introduction and the Emacs Lisp
Reference; they're bundled with Emacs 22 (C-h I to access the Info
Directory).
Juanma
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
[not found] ` <mailman.2737.1183038693.32220.help-gnu-emacs@gnu.org>
@ 2007-06-28 22:32 ` David Kastrup
2007-06-28 23:29 ` Lennart Borgman (gmail)
2007-06-29 14:51 ` Stefan Monnier
0 siblings, 2 replies; 11+ messages in thread
From: David Kastrup @ 2007-06-28 22:32 UTC (permalink / raw)
To: help-gnu-emacs
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> spamfilteraccount@gmail.com wrote:
>> Here are two functions:
>>
>> (defun testfun1 ()
>> (interactive)
>> (setq a '(0 0))
>> (print a))
>>
>> (defun testfun2 ()
>> (interactive)
>> (incf (car a))
>> (print a))
>>
>>
>> I call the first one, a is (0 0).
>> I call the second one, a is (1 0).
>> I call the second one, a is (2 0).
>> I call the first one, a is (2 0).
>>
>> "a" won't get the value (0 0) again until I redefine testfun1.
>>
>> I suspect it is caused be some kind of internal optimization. Is it
>> intentional? It cost me a great deal of head scratching to find out
>> why my program doesn't work.
>
>
> Are you using Emacs 22? Could you then please file a bug report?
There is no bug, and no optimization involved. This is expected and
correct behavior (anything else would be _wrong_). A quoted list is
not regenerated when a function is entered new. A quoted list is
evaluated to a cons cell at _compile_ time. The contents of this cons
cell can be changed with setcar (or, in this case, incf).
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
2007-06-28 22:32 ` David Kastrup
@ 2007-06-28 23:29 ` Lennart Borgman (gmail)
2007-06-29 14:51 ` Stefan Monnier
1 sibling, 0 replies; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2007-06-28 23:29 UTC (permalink / raw)
To: David Kastrup; +Cc: help-gnu-emacs
David Kastrup wrote:
> "Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>
>> spamfilteraccount@gmail.com wrote:
>>> Here are two functions:
>>>
>>> (defun testfun1 ()
>>> (interactive)
>>> (setq a '(0 0))
>>> (print a))
>>>
>>> (defun testfun2 ()
>>> (interactive)
>>> (incf (car a))
>>> (print a))
>>>
>>>
>>> I call the first one, a is (0 0).
>>> I call the second one, a is (1 0).
>>> I call the second one, a is (2 0).
>>> I call the first one, a is (2 0).
>>>
>>> "a" won't get the value (0 0) again until I redefine testfun1.
>>>
>>> I suspect it is caused be some kind of internal optimization. Is it
>>> intentional? It cost me a great deal of head scratching to find out
>>> why my program doesn't work.
>>
>> Are you using Emacs 22? Could you then please file a bug report?
>
> There is no bug, and no optimization involved. This is expected and
> correct behavior (anything else would be _wrong_). A quoted list is
> not regenerated when a function is entered new. A quoted list is
> evaluated to a cons cell at _compile_ time. The contents of this cons
> cell can be changed with setcar (or, in this case, incf).
Ah, yes. I forgot about this case, but Juanma explained this before here.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
2007-06-28 22:32 ` David Kastrup
2007-06-28 23:29 ` Lennart Borgman (gmail)
@ 2007-06-29 14:51 ` Stefan Monnier
2007-06-29 20:00 ` David Kastrup
1 sibling, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2007-06-29 14:51 UTC (permalink / raw)
To: help-gnu-emacs
> A quoted list is evaluated to a cons cell at _compile_ time.
Actually, it's done at "read" time (aka "load" time). I.e. when you load
the .el or .elc file, or when you hit C-x C-e on the (defun ...).
> The contents of this cons cell can be changed with setcar (or, in this
> case, incf).
And I consider this as a bug, actually, but a known one that's a bit
difficult to fix satisfactorily.
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
2007-06-29 14:51 ` Stefan Monnier
@ 2007-06-29 20:00 ` David Kastrup
2007-07-12 19:36 ` Stefan Monnier
0 siblings, 1 reply; 11+ messages in thread
From: David Kastrup @ 2007-06-29 20:00 UTC (permalink / raw)
To: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> A quoted list is evaluated to a cons cell at _compile_ time.
>
> Actually, it's done at "read" time (aka "load" time). I.e. when you
> load the .el or .elc file, or when you hit C-x C-e on the (defun
> ...).
Sure.
>> The contents of this cons cell can be changed with setcar (or, in
>> this case, incf).
>
> And I consider this as a bug, actually, but a known one that's a bit
> difficult to fix satisfactorily.
Why would that be a bug?
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
2007-06-29 20:00 ` David Kastrup
@ 2007-07-12 19:36 ` Stefan Monnier
2007-07-12 19:50 ` Lennart Borgman (gmail)
[not found] ` <mailman.3415.1184269869.32220.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 11+ messages in thread
From: Stefan Monnier @ 2007-07-12 19:36 UTC (permalink / raw)
To: help-gnu-emacs
>>> A quoted list is evaluated to a cons cell at _compile_ time.
>>
>> Actually, it's done at "read" time (aka "load" time). I.e. when you
>> load the .el or .elc file, or when you hit C-x C-e on the (defun
>> ...).
> Sure.
>>> The contents of this cons cell can be changed with setcar (or, in
>>> this case, incf).
>>
>> And I consider this as a bug, actually, but a known one that's a bit
>> difficult to fix satisfactorily.
> Why would that be a bug?
Because immediate literal values such as '(1 2) are conceptually part of the
code rather than part of the data, so setcar on them will change program
code which is against my religion.
Of course, this might be considered moot since my religion also
opposes setcar (and aset on strings).
Stefan
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
2007-07-12 19:36 ` Stefan Monnier
@ 2007-07-12 19:50 ` Lennart Borgman (gmail)
[not found] ` <mailman.3415.1184269869.32220.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 11+ messages in thread
From: Lennart Borgman (gmail) @ 2007-07-12 19:50 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
> Because immediate literal values such as '(1 2) are conceptually part of the
> code rather than part of the data, so setcar on them will change program
> code which is against my religion.
>
> Of course, this might be considered moot since my religion also
> opposes setcar (and aset on strings).
All religions (as well as political parties) have and should have their
contradictions. That is life.
I would say that the first part, changing '(1 2), is very confusing.
Consider debugging for example.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Strange incf behavior in Emacs 22. Intentional?
[not found] ` <mailman.3415.1184269869.32220.help-gnu-emacs@gnu.org>
@ 2007-07-12 22:05 ` David Kastrup
0 siblings, 0 replies; 11+ messages in thread
From: David Kastrup @ 2007-07-12 22:05 UTC (permalink / raw)
To: help-gnu-emacs
"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
>> Because immediate literal values such as '(1 2) are conceptually part of the
>> code rather than part of the data, so setcar on them will change program
>> code which is against my religion.
>>
>> Of course, this might be considered moot since my religion also
>> opposes setcar (and aset on strings).
>
>
> All religions (as well as political parties) have and should have
> their contradictions. That is life.
>
> I would say that the first part, changing '(1 2), is very
> confusing. Consider debugging for example.
"Doctor, it hurts when I do this." "Don't do this then".
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-07-12 22:05 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-28 12:41 Strange incf behavior in Emacs 22. Intentional? spamfilteraccount
2007-06-28 12:46 ` Thien-Thi Nguyen
2007-06-28 13:51 ` Lennart Borgman (gmail)
2007-06-28 13:54 ` Juanma Barranquero
[not found] ` <mailman.2737.1183038693.32220.help-gnu-emacs@gnu.org>
2007-06-28 22:32 ` David Kastrup
2007-06-28 23:29 ` Lennart Borgman (gmail)
2007-06-29 14:51 ` Stefan Monnier
2007-06-29 20:00 ` David Kastrup
2007-07-12 19:36 ` Stefan Monnier
2007-07-12 19:50 ` Lennart Borgman (gmail)
[not found] ` <mailman.3415.1184269869.32220.help-gnu-emacs@gnu.org>
2007-07-12 22:05 ` David Kastrup
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).