From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Wellons Newsgroups: gmane.emacs.devel Subject: [PATCH] Use closures in hashcash.el Date: Mon, 11 Mar 2019 23:12:47 -0400 Message-ID: <20190312031247.clqdquwuempidmt3@nullprogram.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="56543"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: NeoMutt/20170113 (1.7.2) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 12 04:25:25 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h3Y2d-000EZU-J9 for ged-emacs-devel@m.gmane.org; Tue, 12 Mar 2019 04:25:23 +0100 Original-Received: from localhost ([127.0.0.1]:44309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3Y2c-0006Vn-Bc for ged-emacs-devel@m.gmane.org; Mon, 11 Mar 2019 23:25:22 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:54226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3Xqa-0004vr-83 for emacs-devel@gnu.org; Mon, 11 Mar 2019 23:12:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3XqZ-0003nk-Ai for emacs-devel@gnu.org; Mon, 11 Mar 2019 23:12:56 -0400 Original-Received: from mail.nullprogram.com ([192.241.191.137]:35972) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h3XqZ-0003mz-6G for emacs-devel@gnu.org; Mon, 11 Mar 2019 23:12:55 -0400 Original-Received: from nullprogram.com (localhost [127.0.0.1]) by mail.nullprogram.com (Postfix) with ESMTPS id 8FFD8C5B80 for ; Mon, 11 Mar 2019 23:12:48 -0400 (EDT) Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 192.241.191.137 X-Mailman-Approved-At: Mon, 11 Mar 2019 23:24:47 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:234089 Archived-At: hashcash.el was switched over to lexical scope in da94ea9, but it still uses an old workaround of dynamically constructing lambda expression "closures" using backquote. The following patch changes these into proper closures. I discovered this because, in the first case, the backquote lambda is actually constructed incorrectly. The callback function object is evaluated an extra time when the callback is invoked. That's harmless for non-closures and byte-compiled functions, but it doesn't work with interpreted closures. I've made this same error myself and have written about it here: Emacs Lisp Lambda Expressions Are Not Self-Evaluating https://nullprogram.com/blog/2018/02/22/ diff --git a/lisp/mail/hashcash.el b/lisp/mail/hashcash.el index 59200eaab8..77b4a429d2 100644 --- a/lisp/mail/hashcash.el +++ b/lisp/mail/hashcash.el @@ -182,8 +182,8 @@ Return immediately. Call CALLBACK with process and result when ready." (setq hashcash-process-alist (cons (cons process (current-buffer)) hashcash-process-alist)) - (set-process-filter process `(lambda (process output) - (funcall ,callback process output)))) + (set-process-filter process (lambda (process output) + (funcall callback process output)))) (funcall callback nil nil))) (defun hashcash-check-payment (token str val) @@ -244,8 +244,8 @@ Only start calculation. Results are inserted when ready." (hashcash-generate-payment-async (hashcash-payment-to arg) (hashcash-payment-required arg) - `(lambda (process payment) - (hashcash-insert-payment-async-2 ,(current-buffer) process payment))))) + (lambda (process payment) + (hashcash-insert-payment-async-2 (current-buffer) process payment))))) (defun hashcash-insert-payment-async-2 (buffer process pay) (when (buffer-live-p buffer)