From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: binding question Date: Sun, 06 Oct 2013 17:35:30 +0800 Message-ID: <87li267ndp.fsf@ericabrahamsen.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1381052102 13500 80.91.229.3 (6 Oct 2013 09:35:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 6 Oct 2013 09:35:02 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 06 11:35:06 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VSkjx-0004CE-VA for geh-help-gnu-emacs@m.gmane.org; Sun, 06 Oct 2013 11:35:06 +0200 Original-Received: from localhost ([::1]:54286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VSkjx-00059Q-Ia for geh-help-gnu-emacs@m.gmane.org; Sun, 06 Oct 2013 05:35:05 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VSkjh-000593-VB for help-gnu-emacs@gnu.org; Sun, 06 Oct 2013 05:34:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VSkjb-0001yt-QR for help-gnu-emacs@gnu.org; Sun, 06 Oct 2013 05:34:49 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:44356) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VSkjb-0001yn-JR for help-gnu-emacs@gnu.org; Sun, 06 Oct 2013 05:34:43 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VSkjZ-0003zj-Lo for help-gnu-emacs@gnu.org; Sun, 06 Oct 2013 11:34:41 +0200 Original-Received: from 114.250.118.156 ([114.250.118.156]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 06 Oct 2013 11:34:41 +0200 Original-Received: from eric by 114.250.118.156 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 06 Oct 2013 11:34:41 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 48 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 114.250.118.156 User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:SmRS565jLdQsmXZFj5GmojXHVxo= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:93865 Archived-At: 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