* Contributing (setf (assoc ...))
@ 2009-05-09 13:55 Daniel Pittman
2009-05-09 14:23 ` Lennart Borgman
2009-11-18 14:23 ` Stefan Monnier
0 siblings, 2 replies; 4+ messages in thread
From: Daniel Pittman @ 2009-05-09 13:55 UTC (permalink / raw
To: emacs-devel
G'day.
I recently wanted to update as associative list, but apparently Emacs
doesn't presently have an implementation of (setf (assoc ...)), at least
in the snapshot I use.
I believe I have paperwork on file already with the FSF for Emacs, even
assuming that this is large enough to require such paperwork:
(defsetf assoc (key place) (value)
(let ((s1 (gensym)))
`(let ((,s1 (assoc ,key ,place)))
(if ,s1 (setf (second ,s1) ,value)
(push (list ,key ,value) ,place)))))
That implementation should work fine in all circumstances, I believe,
and passes my local testing.
Um, generally speaking there doesn't seem to be anything like a test
suite for Emacs Lisp code that I could locate. Did I miss something, or
is it generally the practice to just get it right? ;)
Regards,
Daniel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Contributing (setf (assoc ...))
2009-05-09 13:55 Contributing (setf (assoc ...)) Daniel Pittman
@ 2009-05-09 14:23 ` Lennart Borgman
2009-11-18 14:23 ` Stefan Monnier
1 sibling, 0 replies; 4+ messages in thread
From: Lennart Borgman @ 2009-05-09 14:23 UTC (permalink / raw
To: Daniel Pittman; +Cc: emacs-devel
On Sat, May 9, 2009 at 3:55 PM, Daniel Pittman <daniel@rimspace.net> wrote:
> Um, generally speaking there doesn't seem to be anything like a test
> suite for Emacs Lisp code that I could locate. Did I miss something, or
> is it generally the practice to just get it right? ;)
There is a subdirectory emacs/test if you check out the sources. There
is however not very much there yet if I remember correctly.
On EmacsWiki you can find this page:
http://www.emacswiki.org/emacs/UnitTesting
And I have a modified version of the ert test library in nXhtml. This
modified version adds some things I need for testing syntax
fontification.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Contributing (setf (assoc ...))
2009-05-09 13:55 Contributing (setf (assoc ...)) Daniel Pittman
2009-05-09 14:23 ` Lennart Borgman
@ 2009-11-18 14:23 ` Stefan Monnier
2009-11-18 15:00 ` David Kastrup
1 sibling, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2009-11-18 14:23 UTC (permalink / raw
To: Daniel Pittman; +Cc: emacs-devel
> (defsetf assoc (key place) (value)
> (let ((s1 (gensym)))
> `(let ((,s1 (assoc ,key ,place)))
> (if ,s1 (setf (second ,s1) ,value)
> (push (list ,key ,value) ,place)))))
This code has 2 problems:
1- association lists have elements of the form (KEY . VAL) rather than
(KEY VAL), so rather than (list ,key ,value) it should use
(cons ,key ,value) and rather than (second ,s1) it should use
(cdr ,s1).
2- it's unsatisfactory iin that it's asymmetric w.r.t assoc; because
assoc returns not just the VAL associated to a KEY but the whole
(KEY . VAL).
Usually (setf <foo> <bar>) should imply that a subsequent evaluation
of <foo> should return the value of <bar>, but here this can't be the
case. IOW `assoc' is inherently incompatible with setf.
Problem 1 is trivial, obviously. Problem 2 is more philosophical than
anything, but it makes the macro unsatifactory.
WDPT?
Stefan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Contributing (setf (assoc ...))
2009-11-18 14:23 ` Stefan Monnier
@ 2009-11-18 15:00 ` David Kastrup
0 siblings, 0 replies; 4+ messages in thread
From: David Kastrup @ 2009-11-18 15:00 UTC (permalink / raw
To: emacs-devel
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (defsetf assoc (key place) (value)
>> (let ((s1 (gensym)))
>> `(let ((,s1 (assoc ,key ,place)))
>> (if ,s1 (setf (second ,s1) ,value)
>> (push (list ,key ,value) ,place)))))
>
> This code has 2 problems:
> 1- association lists have elements of the form (KEY . VAL) rather than
> (KEY VAL), so rather than (list ,key ,value) it should use
> (cons ,key ,value) and rather than (second ,s1) it should use
> (cdr ,s1).
> 2- it's unsatisfactory iin that it's asymmetric w.r.t assoc; because
> assoc returns not just the VAL associated to a KEY but the whole
> (KEY . VAL).
> Usually (setf <foo> <bar>) should imply that a subsequent evaluation
> of <foo> should return the value of <bar>, but here this can't be the
> case. IOW `assoc' is inherently incompatible with setf.
>
> Problem 1 is trivial, obviously. Problem 2 is more philosophical than
> anything, but it makes the macro unsatifactory.
>
> WDPT?
The above does not have the right setf semantics. One would need to
write
(setf (cdr (assoc key ...)) value)
in order to set just the value of a key value pair. If one does, it is
perfectly fine that the return value is just value.
Or one would have to use something like
(setf (assoc-default key ...) value)
--
David Kastrup
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-11-18 15:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-09 13:55 Contributing (setf (assoc ...)) Daniel Pittman
2009-05-09 14:23 ` Lennart Borgman
2009-11-18 14:23 ` Stefan Monnier
2009-11-18 15:00 ` David Kastrup
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.