Subject: bug#77048: 30.1; Macro `cl-load-time-value` malfunctioning at compile-time and runtime

From: Stefan Monnier <[email-masked]>
Date: Mon, 17 Mar 2025 23:13:37 -0400

> I created a minimal package to reproduce this issue, please check that
> out: https://github.com/bohonghuang/cl-load-time-value-test.git
>
> In my test (with native compilation), simply running command `ltvt-test`
> results in an error:
>
> funcall-interactively: Symbol’s value as variable is void:
> --cl-load-time--0

I don't see that.  Can you show in detail the steps you go through?
I did put your file in ~/tmp/foo.el, then byte-compiled it, then did

    emacs -Q -l ~/tmp/foo

then waited a little for the native compiler to kick in, and then

    M-x ltvt-test RET

which did nothing.
Doing that `M-x` a second time gave me the message "Test message".
Same thing without native compilation.

>> Hmm... I don't quite follow: `cl-load-time-value` does not perform
>> compile-time evaluation but load-time evaluation, as its name suggests.
>> Maybe you could/should use `eval-when-compile` instead?
>
> You are right. My description was inaccurate, but the general idea is
> that I hope the form in `cl-load-time-value` can be evaluated before
> the function is actually called, and return an object that is always
> `eq`.  Maybe it's due to the load-time evaluation that makes using
> `cl-load-time-value` sometimes be more convenient, as it does not
> require wrapping all functions in the same file as the caller on the
> call chain within `eval-when-compile`, just as I provided in the example
> package.

In my experience, it's always quite easy to rewrite the code without the
use of `cl-load-time-value` by moving that code outside to some earlier
`defconst`.  So I do that because I shudder at the idea of relying on
the hackish implementation of `cl-load-time-value`.  🙂

I think its main use case is in macros where you may not have the
liberty to move the code to some earlier `defconst`, so you're stuck
asking `cl-load-time-value` to do it for you.

        Stefan