GNU bug report logs - #77048
30.1; Macro `cl-load-time-value` malfunctioning at compile-time and runtime

Previous Next

Package: emacs;

Reported by: Bohong Huang <bohonghuang <at> qq.com>

Date: Sun, 16 Mar 2025 12:10:03 UTC

Severity: normal

Found in version 30.1

Full log


View this message in rfc822 format

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Bohong Huang <bohonghuang <at> qq.com>
Cc: 77048 <at> debbugs.gnu.org
Subject: bug#77048: 30.1; Macro `cl-load-time-value` malfunctioning at compile-time and runtime
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





This bug report was last modified 90 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.