emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Use closures in hashcash.el


From: Christopher Wellons
Subject: [PATCH] Use closures in hashcash.el
Date: Mon, 11 Mar 2019 23:12:47 -0400
User-agent: NeoMutt/20170113 (1.7.2)

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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]