all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Daniel Pittman <daniel@rimspace.net>
Cc: emacs-devel@gnu.org
Subject: Re: Contributing (setf (assoc ...))
Date: Wed, 18 Nov 2009 09:23:03 -0500	[thread overview]
Message-ID: <jwv1vjvlxws.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87my9m4bz1.fsf@rimspace.net> (Daniel Pittman's message of "Sat,  09 May 2009 23:55:46 +1000")

> (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




  parent reply	other threads:[~2009-11-18 14:23 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 [this message]
2009-11-18 15:00   ` David Kastrup

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=jwv1vjvlxws.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=daniel@rimspace.net \
    --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.