From: David Kastrup <dak@gnu.org>
To: emacs-devel@gnu.org
Subject: Re: Contributing (setf (assoc ...))
Date: Wed, 18 Nov 2009 16:00:35 +0100 [thread overview]
Message-ID: <87lji3lvxo.fsf@lola.goethe.zz> (raw)
In-Reply-To: jwv1vjvlxws.fsf-monnier+emacs@gnu.org
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
prev parent reply other threads:[~2009-11-18 15:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87lji3lvxo.fsf@lola.goethe.zz \
--to=dak@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.