all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#60315: 28.2; Byte-compiler warning for free variable
@ 2022-12-25 17:07 Drew Adams
  0 siblings, 0 replies; only message in thread
From: Drew Adams @ 2022-12-25 17:07 UTC (permalink / raw)
  To: 60315

You might not consider this a bug, or you might consider it not worth
trying to fix.  That's fine by me.  I think it's worth reporting, at
least.  Maybe something can be done for it, or maybe you can let me know
a good way to work around it.

Unlike `defvar', `defconst', alters the value each time it's evaluated.
E.g., if you load a file with (defconst foo bar "...") more than once
then the value of `foo' gets set each time to whatever is the current
value of `bar'.  That's normal and desirable (and consistent with other
Lisps, such as CL).

How to ensure that a defconst sets the value only once, when the file
it's in is loaded?  A defvar does that, but a defconst does not.

Maybe there's a better way, but I've been using this so far:

  (unless (boundp 'foo) (defconst foo bar "..."))

But that results in this byte-compiler warning:

 In blah-fun:
 toto.el:236:34:Warning: reference to free variable
     `foo'

An alternative is to use a defvar and just say in its doc string that
it's intended as a constant (don't set it etc.).  Maybe that's less
confusing to users than seeing the warning?  Dunno.

In GNU Emacs 28.2 (build 2, x86_64-w64-mingw32)
 of 2022-09-13 built on AVALON
Windowing system distributor 'Microsoft Corp.', version 10.0.19044
System Description: Microsoft Windows 10 Pro (v10.0.2009.19044.2364)

Configured using:
 'configure --with-modules --without-dbus --with-native-compilation
 --without-compress-install CFLAGS=-O2'

Configured features:
ACL GIF GMP GNUTLS HARFBUZZ JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND THREADS TIFF TOOLKIT_SCROLL_BARS
XPM ZLIB

(NATIVE_COMP present but libgccjit not available)






^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-25 17:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-25 17:07 bug#60315: 28.2; Byte-compiler warning for free variable Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.