all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Barry Margolin <barmar@alum.mit.edu>
To: help-gnu-emacs@gnu.org
Subject: Re: DynamicBindingVsLexicalBinding
Date: Wed, 16 Oct 2013 10:26:54 -0400	[thread overview]
Message-ID: <barmar-AF232A.10265416102013@news.eternal-september.org> (raw)
In-Reply-To: mailman.4127.1381928277.10748.help-gnu-emacs@gnu.org

In article <mailman.4127.1381928277.10748.help-gnu-emacs@gnu.org>,
 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 ***


  parent reply	other threads:[~2013-10-16 14:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-12 17:56 DynamicBindingVsLexicalBinding Andreas Röhler
2013-10-12 18:35 ` DynamicBindingVsLexicalBinding Dmitry Gutov
2013-10-12 20:53   ` DynamicBindingVsLexicalBinding Drew Adams
2013-10-13  5:09     ` DynamicBindingVsLexicalBinding Thien-Thi Nguyen
2013-10-13  7:54   ` DynamicBindingVsLexicalBinding Andreas Röhler
2013-10-13 13:46     ` DynamicBindingVsLexicalBinding Kai Großjohann
2013-10-13 16:21       ` DynamicBindingVsLexicalBinding Drew Adams
2013-10-14 11:21         ` DynamicBindingVsLexicalBinding Phillip Lord
2013-10-14 13:45           ` DynamicBindingVsLexicalBinding Drew Adams
2013-10-14 16:05             ` DynamicBindingVsLexicalBinding Phillip Lord
2013-10-14 21:32           ` DynamicBindingVsLexicalBinding Kai Großjohann
2013-10-15 11:27             ` DynamicBindingVsLexicalBinding Phillip Lord
2013-10-15 20:43               ` DynamicBindingVsLexicalBinding Kai Großjohann
2013-10-16 12:57                 ` DynamicBindingVsLexicalBinding Phillip Lord
     [not found]                 ` <mailman.4127.1381928277.10748.help-gnu-emacs@gnu.org>
2013-10-16 14:26                   ` Barry Margolin [this message]
     [not found]       ` <mailman.3929.1381681317.10748.help-gnu-emacs@gnu.org>
2013-10-14 11:27         ` DynamicBindingVsLexicalBinding Rustom Mody
2013-10-14 11:15 ` DynamicBindingVsLexicalBinding Phillip Lord
     [not found] <mailman.3891.1381600459.10748.help-gnu-emacs@gnu.org>
2013-10-13  3:34 ` DynamicBindingVsLexicalBinding Barry Margolin

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=barmar-AF232A.10265416102013@news.eternal-september.org \
    --to=barmar@alum.mit.edu \
    --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.