From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Subject: binding question
Date: Sun, 06 Oct 2013 17:35:30 +0800 [thread overview]
Message-ID: <87li267ndp.fsf@ericabrahamsen.net> (raw)
I've got a variable binding scenario that I thought would be easy to
resolve, but is giving me trouble. I have the feeling that this scenario
represents some sort of Lesson 1 in How Bindings Work, but I'm still not
sure of the proper solution.
The general situation is: I want to start with a list template stored in
a variable. Another function in this library starts with the template,
modifies it a few times, then does something with the modified version.
Every time this function is called, it should start with a "fresh" copy
of the template.
Clearly the following doesn't work: it actually modifies the original
list-template.
(defvar list-template
'(item ((with . "some")
(sub . "lists"))
nil (other things will go here)))
(defun main-entry-function ()
;; obviously this doesn't work as defvars are always special
(let ((list-template list-template))
;; list-template is accessed dynamically in the following functions
(modify-list-template)
(modify-list-template-again)
(do-something-with-modified-list-template)))
The other option would be to pass list-template as an argument to each
of these functions. I guess each call would then have to look like:
(setq list-template (modify-list-template list-template))
This seems ugly, and it won't necessarily be easy to ensure the
modifying functions end by returning the new value of list-template.
What's the best way of handling this? And is there one "right" solution
for both dynamic and lexical binding?
Thanks!
Eric
PS: The wiki[1] mentions pretty much exactly my scenario, but doesn't
actually say what should be done.
[1]
http://www.emacswiki.org/emacs/DynamicBindingVsLexicalBinding#toc4
next reply other threads:[~2013-10-06 9:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-06 9:35 Eric Abrahamsen [this message]
2013-10-06 10:14 ` binding question Thien-Thi Nguyen
2013-10-06 14:03 ` Eric Abrahamsen
2013-10-06 14:45 ` Stefan Monnier
2013-10-06 12:39 ` Michael Heerdegen
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=87li267ndp.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--cc=help-gnu-emacs@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.