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: defining a setter function with gv.el Date: Thu, 30 Aug 2012 20:59:33 -0400 Message-ID: References: <87ehmsyj2b.fsf@googlemail.com> <87vcg4cij6.fsf@googlemail.com> <87obls1i30.fsf@kanis.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1346374786 9072 80.91.229.3 (31 Aug 2012 00:59:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Aug 2012 00:59:46 +0000 (UTC) Cc: emacs devel To: Ivan Kanis Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Aug 31 02:59:47 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T7FaH-0002XM-DO for ged-emacs-devel@m.gmane.org; Fri, 31 Aug 2012 02:59:41 +0200 Original-Received: from localhost ([::1]:57346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7FaF-0000iQ-6j for ged-emacs-devel@m.gmane.org; Thu, 30 Aug 2012 20:59:39 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7FaC-0000iK-J4 for emacs-devel@gnu.org; Thu, 30 Aug 2012 20:59:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T7FaB-00084i-Hg for emacs-devel@gnu.org; Thu, 30 Aug 2012 20:59:36 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:23805) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7FaB-00083a-CU for emacs-devel@gnu.org; Thu, 30 Aug 2012 20:59:35 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av0EAG6Zu09FxKEe/2dsb2JhbABEtBGBCIIVAQEEAVYjBQsLNBIUGA0kiBwFugmQRAOjM4FYgwU X-IronPort-AV: E=Sophos;i="4.75,637,1330923600"; d="scan'208";a="197126876" Original-Received: from 69-196-161-30.dsl.teksavvy.com (HELO pastel.home) ([69.196.161.30]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 30 Aug 2012 20:59:34 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id C456C59407; Thu, 30 Aug 2012 20:59:33 -0400 (EDT) In-Reply-To: <87obls1i30.fsf@kanis.fr> (Ivan Kanis's message of "Thu, 30 Aug 2012 18:05:07 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.182 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152906 Archived-At: > (setq lexical-binding t) BTW, don't do that: instead, set it as a file-local variable with "-*- lexical-binding: t -*-". > (defun alist-get (key alist) > "Get the value associated to KEY in ALIST." > (declare > (gv-expander > (lambda (do) > (macroexp-let2 macroexp-copyable-p k key > (gv-letplace (getter setter) alist > (macroexp-let2 nil p `(assoc ,k ,getter) > (funcall do `(cdr ,p) > (lambda (v) > `(if ,p (setcdr ,p ,v) > ,(funcall setter > `(cons (cons ,k ,v) ,getter)))))))))))) The (declare ...) form is used to give auxiliary info about the function you're defining (such as info about how to indent it, how Edebug needs to instrument it, or in our case how `setf' or `push' can "set" it). The function itself ignores it. So the definition above is like (defun alist-get (key alist) "Get the value associated to KEY in ALIST.") I.e. you removed the body of the function (which was the last line: (cdr (assoc key alist)) ). > Yes this is what needs to be generated. I don't understand why there > are two lambdas in alist-get. See C-h f gv-define-expander RET and `gv-get'. > Is there any chance you would uncomment this function so that I can use > it in my code? There's a chance, but if you could explain why (push (cons KEY VAL) ALIST) doesn't work for you, that would help, Stefan