all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: emacs-devel@gnu.org
Subject: dynamic let closure not possible with `dlet', instead use lexical let and `setq'
Date: Fri, 05 Jan 2024 06:04:41 +0100	[thread overview]
Message-ID: <87plygbcba.fsf@dataswamp.org> (raw)

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




                 reply	other threads:[~2024-01-05  5:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87plygbcba.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.