emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The purpose of makunbound


From: Kelly Dean
Subject: Re: The purpose of makunbound
Date: Wed, 18 Feb 2015 18:53:31 +0000

Stefan Monnier wrote:
> Why would that be an error?

Because of a classic mistake with dynamic binding:
(defvar bar nil)
(defun foo ()
  (if something-rare...
      (makunbound 'bar)) ; Intent is global
  (do-something))

(let ((bar (something))) ; Intent is lexical
  (do-some-stuff)
  (foo)
  (if bar ; Oops
      (some-other-stuff)))

Well the classic is with «set», not makunbound, but the problem is the same.

There are legitimate cases for using «set» in dynamic «let», so the interpreter 
must allow it, and you just have to deal with the possibility of that kind of 
mistake. But for makunbound, if there are no legitimate use cases, then the 
interpreter could catch it.

> How often have you bumped into that error?

Never.

> And remember: a (dynamically scoped) `let' does not necessarily mean to
> make a local binding, it can also be understood to mean to temporarily
> change the global variable
[snip]
> You talk about "global variable" vs "dynamic variable", but that
> difference is only in your head because of the interpretation you chose.

For single-threaded code, there's no difference, but for multi-threaded, there 
is, which you already mentioned. Why have inconsistent interpretations for 
single vs. multi, when you can have a consistent one for both?

And aren't you planning to add multi-threading to Emacs?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]