emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Contributing (setf (assoc ...))


From: Stefan Monnier
Subject: Re: Contributing (setf (assoc ...))
Date: Wed, 18 Nov 2009 09:23:03 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]