From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Barry Margolin Newsgroups: gmane.emacs.help Subject: Re: DynamicBindingVsLexicalBinding Date: Wed, 16 Oct 2013 10:26:54 -0400 Organization: A noiseless patient Spider Message-ID: References: <52598D4A.2010901@easy-emacs.de> <871u3qjq0j.fsf@yandex.ru> <525A51BD.5040903@easy-emacs.de> <525AA42B.6030006@gmx.net> <6d5df021-be1e-40a2-966a-548a7ee9deb3@default> <87txgk85em.fsf@zerg32.ncl.ac.uk> <525C62D9.8070702@gmx.net> <87ppr6oju7.fsf@zerg32.ncl.ac.uk> <525DA8E6.8070607@gmx.net> NNTP-Posting-Host: plane.gmane.org X-Trace: ger.gmane.org 1381934638 24626 80.91.229.3 (16 Oct 2013 14:43:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Oct 2013 14:43:58 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 16 16:44:02 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 1VWSKP-0005tu-Aw for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Oct 2013 16:44:01 +0200 Original-Received: from localhost ([::1]:47530 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWS7f-0004HS-Ry for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Oct 2013 10:30:51 -0400 Original-Path: usenet.stanford.edu!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!barmar.motzarella.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Injection-Info: barmar.motzarella.org; posting-host="2be9e9f5dd9af768b8861af71b85fc28"; logging-data="18182"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19qYJaBwjLhXTncvnhcVyTf" User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Cancel-Lock: sha1:GNGDat6ENiDp8qPFLelpfXAzmM0= Original-Xref: usenet.stanford.edu gnu.emacs.help:201768 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:94037 Archived-At: In article , phillip.lord@newcastle.ac.uk (Phillip Lord) wrote: > Perhaps my understanding is not complete, but I always thought that > dynamic and static binding was about variables that are unbound. If we > have global variables with mutable state, then as far as I can see, you > could do something equivalent with either. > > So, this... > > (defun perldoc () > (interactive) > (require 'man) > (let ((manual-program "perldoc")) > (call-interactively 'man))) > > is nearly equivalent to > > (defun perldoc() > (interactive) > (require 'man) > (let ((old manual-program)) > (setq manual-program "perldoc") > (call-interactively 'man) > (setq manual-program old)) > > > If we were multi-threaded, then AFAICT, the let version would be > cleaner -- as the altered manual-program is *only* in the dynamic > environment of the call to the perldoc command. So another call to the > man function would be unaffected. While the second changes global state, > and then changes it back. But, we aren't. You also need unwind-protect to ensure that the value is reverted if the code aborts. With that fix, it's essentially how most implementations of dynamic binding worked in single-threaded Lisps. But multi-threaded Lisps need to add hooks into thread switching. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***