The GNU Emacs Lisp Reference Manual, 12.5 Defining Global Variables:
If you use a
defconst
ordefvar
special form while the variable has a local binding (made withlet
, or a function argument), it sets the local binding rather than the global binding.
But when I tried it in *scratch*
:
(defun f (some-symbol)
(defconst some-symbol 1412)
some-symbol)
;; ==> f
(f 0)
;; ==> 0
some-symbol
;; ==> 1412
It seems that (defconst some-symbol 1412)
didn't set the local value of some-symbol
(so that (f 0)
evaluates to 0
), instead it made the some-symbol
at top level evaluate to 1412
.
Do I misunderstand the definitions of local binding and global binding?
Update
Another example that seems to work fine for @dalanicolai:
Although
defconst
does work as documented when using it withlet
:(let ((some-symbol 0)) (defconst some-symbol 1412) some-symbol)
returns 1412.
but behaves weirdly in my Emacs:
*** Welcome to IELM *** Type (describe-mode) for help.
ELISP> (let ((some-symbol 0))
(defconst some-symbol 1412)
some-symbol)
0 (#o0, #x0, ?\C-@)
ELISP> (let ((some-symbol 0))
(defconst some-symbol 1412)
some-symbol)
1412 (#o2604, #x584)
ELISP>
emacs-version: 28.2
system-configuration: x86_64-w64-mingw32