emacs-devel
[Top][All Lists]
Advanced

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

Re: A combination of defmacro, functionp, and quoted lambdas yields diff


From: Clément Pit-Claudel
Subject: Re: A combination of defmacro, functionp, and quoted lambdas yields different results on consecutive evaluations
Date: Mon, 26 Feb 2018 00:40:05 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

On 2018-02-25 22:18, Stefan Monnier wrote:
>> * In a new file test-macro.el, write this:
>>   
>>   (defmacro mmm (f)
>>     `(function ,f))
>>   (provide 'test-macro)
>>
>> * In a new file test.el, write this
>>
>>   (with-eval-after-load 'test-macro
>>     (let ((out (mmm (lambda ()))))
>>       (message "with-eval-after-load: %S" out)))
>>
>>   (load (expand-file-name "test-macro.el"))
> 
> This is not supposed to work: your test.el uses `mmm` before it gets
> defined by the subsequent `load`.

Uh, really? But the body of with-eval-after-load is (supposed to be) evaluated 
after the FILE argument is loaded, not before, right?  `mmm' is only used in 
`with-eval-after-load' in the code above.  

The manual says the following about with-eval-after-load:

     This macro arranges to evaluate BODY at the end of loading the file
     LIBRARY, each time LIBRARY is loaded.  If LIBRARY is already
     loaded, it evaluates BODY right away.

Am I misunderstanding something?  In what sense does the code above use `mmm' 
before it gets defined?  And, does that mean that with-eval-after-load can't be 
used to run a macro after the package defining it has been loaded?

I guess what's confusing to me is that calling with-eval-after-load seems to be 
diffrent from directly adding a form to after-load-alist, as shown by the fact 
that the following snippet works fine:

  (add-to-list
   'after-load-alist
   (list 'test-macro
         (lambda ()
           (eval '(let ((out (mmm (lambda ()))))
                    (message "after-load-alist: %S" out))))))

  (load (expand-file-name "test-macro.el"))

Why does this behave differently? (and isn't that difference a bug in 
with-eval-after-load?)

> It's true that Emacs doesn't guarantee that it will always fail to work,
> but ... you get what you deserve.

:/ That seems a bit uncalled for, but maybe I'm just misinterpreting a joke?  
"what [I] deserve", in the present case, is multiple hours of my time spent 
debugging an issue raised by a well-meaning Flycheck user, on top of multiple 
hours of the other maintainer's time… I'm not sure in what sense either of us 
deserved that.  Sorry if I'm misunderstanding your comment.

> PS: BTW, moving the `load` earlier may make it work more often but it
>     still wouldn't make it right.  You'd additionally need to replace
>     the `load` by `require` or to wrap it inside a `eval-when-compile`.

Can you explain why?  with-eval-after-load doesn't mention any of these things.

Thanks for your help,
Clément.




reply via email to

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