From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Contributing (setf (assoc ...)) Date: Wed, 18 Nov 2009 09:23:03 -0500 Message-ID: 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 1258555113 5568 80.91.229.12 (18 Nov 2009 14:38:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 18 Nov 2009 14:38:33 +0000 (UTC) Cc: emacs-devel@gnu.org To: Daniel Pittman Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 18 15:38:26 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 1NAlft-0005Ke-4b for ged-emacs-devel@m.gmane.org; Wed, 18 Nov 2009 15:38:25 +0100 Original-Received: from localhost ([127.0.0.1]:39626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAlfr-0006dr-Kb for ged-emacs-devel@m.gmane.org; Wed, 18 Nov 2009 09:38:24 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAlR9-0002qJ-Th for emacs-devel@gnu.org; Wed, 18 Nov 2009 09:23:12 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAlR4-0002ni-2W for emacs-devel@gnu.org; Wed, 18 Nov 2009 09:23:10 -0500 Original-Received: from [199.232.76.173] (port=44072 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAlR3-0002nP-IH for emacs-devel@gnu.org; Wed, 18 Nov 2009 09:23:05 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183]:28707 helo=ironport2-out.pppoe.ca) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NAlR3-0000R4-2Y for emacs-devel@gnu.org; Wed, 18 Nov 2009 09:23:05 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: As4EANeRA0vO+II8/2dsb2JhbACBTdRWhDsEiVc X-IronPort-AV: E=Sophos;i="4.44,765,1249272000"; d="scan'208";a="49592023" Original-Received: from 206-248-130-60.dsl.teksavvy.com (HELO pastel.home) ([206.248.130.60]) by ironport2-out.pppoe.ca with ESMTP; 18 Nov 2009 09:23:04 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id EADB3859F; Wed, 18 Nov 2009 09:23:03 -0500 (EST) In-Reply-To: <87my9m4bz1.fsf@rimspace.net> (Daniel Pittman's message of "Sat, 09 May 2009 23:55:46 +1000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:117174 Archived-At: > (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? Stefan