Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexical let-binding no scope of let variables in subsequent deferred async tasks #54

Open
falkoHein opened this issue Mar 27, 2019 · 3 comments

Comments

@falkoHein
Copy link

I followed the example in the documentation related to lexical binding:
(let ((a (point)))
(deferred:$
(deferred:wait 1000)
(deferred:nextc it
(lambda (x)
(goto-char a)
(insert "here!")))))

In Emacs 26.1 I did a evaluation on region with above code and I got an error like:

deferred error : (void-variable a)

@p3r7
Copy link

p3r7 commented Jan 17, 2020

Hey!

I faced a similar situation.

Here is a workaround:

(let ((a (point)))
  (deferred:$
    (deferred:wait 1000)
    (deferred:nextc it
      `(lambda (x)
         (goto-char ,a)
         (insert "here!")))))

The trick is that deferred:next and deferred:nextc also seem accept a quoted lambda as a expression.

@mukundzare
Copy link

Thanks! I got stuck here too. Never thought of using a quoted expression @p3r7

@Stwerp
Copy link

Stwerp commented Feb 6, 2024

This got me in something I was working on! A function would behave differently if I evaluated the defun from the scratch buffer versus in a setup file. I finally tracked it down to this deferred error. Evaluating from scratch worked fine, but in my setup files, I needed to use the quote. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants