* dynamic let closure not possible with `dlet', instead use lexical let and `setq'
@ 2024-01-05 5:04 Emanuel Berg
0 siblings, 0 replies; only message in thread
From: Emanuel Berg @ 2024-01-05 5:04 UTC (permalink / raw)
To: emacs-devel
1. You can't do a dynamic let closure with `dlet':
(dlet ((oh-ah "oa"))
(defun ohah ()
oh-ah)
(declare-function ohah nil) )
;; (ohah) ; Symbol’s value as variable is void: oh-ah
2. You can do a lexical let closure with `let', but after that
you cannot make any of its lexical variables dynamic with
`dlet':
(let ((some-var 0))
(defun outer ()
(dlet ((some-var 1))
(inner) ))
(declare-function outer nil)
(defun inner ()
some-var)
(declare-function inner nil) )
;; (outer) ; 0
;; (inner) ; 0
3. What you can do, is to keep the variable lexical and use it
like a global variable with `setq':
(let ((some-var 2))
(defun outer ()
(setq some-var 4)
(prog1
(inner)
(setq some-var 2) ))
(declare-function outer nil)
(defun inner ()
some-var)
(declare-function inner nil) )
;; (outer) ; 4
;; (inner) ; 2
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-05 5:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-05 5:04 dynamic let closure not possible with `dlet', instead use lexical let and `setq' Emanuel Berg
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.