From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: Contributing (setf (assoc ...)) Date: Wed, 18 Nov 2009 16:00:35 +0100 Organization: Organization?!? Message-ID: <87lji3lvxo.fsf@lola.goethe.zz> References: <87my9m4bz1.fsf@rimspace.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1258556940 12501 80.91.229.12 (18 Nov 2009 15:09:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 18 Nov 2009 15:09:00 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 18 16:08:53 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NAm9I-0004Ur-94 for ged-emacs-devel@m.gmane.org; Wed, 18 Nov 2009 16:08:48 +0100 Original-Received: from localhost ([127.0.0.1]:54018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAm9H-0003nj-MD for ged-emacs-devel@m.gmane.org; Wed, 18 Nov 2009 10:08:47 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAm2B-0004h9-5R for emacs-devel@gnu.org; Wed, 18 Nov 2009 10:01:27 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAm26-0004cz-B5 for emacs-devel@gnu.org; Wed, 18 Nov 2009 10:01:26 -0500 Original-Received: from [199.232.76.173] (port=51154 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAm26-0004cn-6H for emacs-devel@gnu.org; Wed, 18 Nov 2009 10:01:22 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:51215) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NAm25-0007Ch-JF for emacs-devel@gnu.org; Wed, 18 Nov 2009 10:01:21 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.50) id 1NAm1j-0000Do-Fm for emacs-devel@gnu.org; Wed, 18 Nov 2009 16:00:59 +0100 Original-Received: from p5b2c1f1b.dip.t-dialin.net ([91.44.31.27]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 18 Nov 2009 16:00:59 +0100 Original-Received: from dak by p5b2c1f1b.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 18 Nov 2009 16:00:59 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 39 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: p5b2c1f1b.dip.t-dialin.net X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) Cancel-Lock: sha1:dUQFuw432Z9Bt30oAz2z7cBROHM= X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:117179 Archived-At: Stefan Monnier 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 ) should imply that a subsequent evaluation > of should return the value of , 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