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: pcase-memoize: equal first branch, yet different Date: Mon, 04 Mar 2013 14:33:41 -0500 Message-ID: References: <87hakv6tek.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1362425628 7727 80.91.229.3 (4 Mar 2013 19:33:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 4 Mar 2013 19:33:48 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Mar 04 20:34:13 2013 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 1UCb9I-0005q0-1z for ged-emacs-devel@m.gmane.org; Mon, 04 Mar 2013 20:34:12 +0100 Original-Received: from localhost ([::1]:58924 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCb8w-0002JN-K0 for ged-emacs-devel@m.gmane.org; Mon, 04 Mar 2013 14:33:50 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:51948) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCb8q-0002Bb-Vz for emacs-devel@gnu.org; Mon, 04 Mar 2013 14:33:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCb8p-0005iQ-Uv for emacs-devel@gnu.org; Mon, 04 Mar 2013 14:33:44 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.182]:9398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCb8p-0005iL-Rn for emacs-devel@gnu.org; Mon, 04 Mar 2013 14:33:43 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFFFxLvL/2dsb2JhbABEvw4Xc4IeAQEEAVYoCws0EhQYDYhCBsEtjWGDKQOIYZwZgV6DFQ X-IPAS-Result: Av4EABK/CFFFxLvL/2dsb2JhbABEvw4Xc4IeAQEEAVYoCws0EhQYDYhCBsEtjWGDKQOIYZwZgV6DFQ X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="3003746" Original-Received: from 69-196-187-203.dsl.teksavvy.com (HELO pastel.home) ([69.196.187.203]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 04 Mar 2013 14:33:41 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id EF4E06BF75; Mon, 4 Mar 2013 14:33:41 -0500 (EST) In-Reply-To: <87hakv6tek.fsf@web.de> (Michael Heerdegen's message of "Fri, 01 Mar 2013 16:17:55 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.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:157512 Archived-At: > I get a not so useful message using `pcase' in the following scenario > using trunk: [...] > `(lambda (_event) > (interactive "e") > (pcase ,flag > (`"-" (dired-sort-menu-set-switches "")) > ((or `"t" `"S") > (dired-sort-menu-set-switches ,flag)) > (`"r" > (dired-sort-menu-toggle-reverse))))))) [...] > This works well, but every time I click on a flag, I get this message: > | pcase-memoize: equal first branch, yet different > What does that mean? It's annoying. The pcase macro's expansion can take a significant amount of time to generate. When done during byte-compilation, it's a non-issue, but in the above example it will be done every time you click. For this reason, pcase uses a memoization mechanism, to try and reuse previous expansions. Sadly, this is unreliable because it is difficult to figure out when two chunks of code are actually identical and to do so without incurring undue overheads. The message is just a warning, so you can ignore it. But the better option is to try and fix the underlying problem and make sure pcase is not expanded repeatedly. E.g. using lexical-binding: keymap ,(make-mode-line-mouse-map 'mouse-2 (lambda (_event) (interactive "e") (pcase flag (`"-" (dired-sort-menu-set-switches "")) ((or `"t" `"S") (dired-sort-menu-set-switches ,flag)) (`"r" (dired-sort-menu-toggle-reverse))))))) or using CL's lexical-let: keymap ,(make-mode-line-mouse-map 'mouse-2 (lexical-let ((flag flag)) (lambda (_event) (interactive "e") (pcase flag (`"-" (dired-sort-menu-set-switches "")) ((or `"t" `"S") (dired-sort-menu-set-switches ,flag)) (`"r" (dired-sort-menu-toggle-reverse)))))))) -- Stefan PS: Why do you use (interactive "e") if you then don't use the `event' argument.