From: Didier Verna <didier@didierverna.net>
To: Alan Mackenzie <acm@muc.de>
Cc: Jambunathan K <kjambunathan@gmail.com>, emacs-devel@gnu.org
Subject: Re: Possible defvar bug
Date: Mon, 18 Feb 2013 17:19:10 +0100 [thread overview]
Message-ID: <muxhal9h9xd.fsf@Uzeb.i-did-not-set--mail-host-address--so-tickle-me> (raw)
In-Reply-To: <20130218150954.GA4583@acm.acm> (Alan Mackenzie's message of "Mon, 18 Feb 2013 15:09:54 +0000")
Alan Mackenzie <acm@muc.de> wrote:
> Why would anybody want to defvar a variable inside a let binding which
> also defines it, anyway?
Because you're not responsible for all the code you use; only for the
code you write. Consider this for instance:
| ;;; foo.el
|
| (defvar foo-var 42)
|
| (defun foo-init ()
| ;; do a lot of stuff using foo-var
| )
|
| (foo-init)
|
| (provide 'foo)
BTW, I'm not saying this is good. This is actually pretty bad but I've
seen code like this. If for some reason you're not happy with the
initialization value of foo-var, it makes sense to write:
| (let ((foo-var 51))
| (load "foo.el"))
and although this is not true, I can even understand why some people
would /intuitively/ think it would also change the global init value of
foo-var.
> I would argue that the current behaviour _is_ what is wanted
Yes, I agree. I was referring to the docstring of defvar saying "this
is not what you want", but rather in the sense that "this does not do
what you think it does" (typically: change globally the initial value
of a defvar'ed variable).
Common Lisp behaves that way too:
| * (let ((foo 3))
| (declare (special foo))
| (defvar foo 1)
| (print foo))
|
| 3
| 3
| * foo
|
| debugger invoked on a UNBOUND-VARIABLE in thread
| #<THREAD "main thread" RUNNING {AAFF761}>:
| The variable FOO is unbound.
|
| Type HELP for debugger help, or (SB-EXT:QUIT) to exit from SBCL.
|
| restarts (invokable by number or by possibly-abbreviated name):
| 0: [ABORT] Exit debugger, returning to top level.
|
| (SB-INT:SIMPLE-EVAL-IN-LEXENV FOO #<NULL-LEXENV>)
| 0]
--
ELS 2013: deadline approaching! http://www.european-lisp-symposium.org
Scientific site: http://www.lrde.epita.fr/~didier
Music (Jazz) site: http://www.didierverna.com
next prev parent reply other threads:[~2013-02-18 16:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-18 14:40 Possible defvar bug Tassilo Horn
2013-02-18 14:47 ` Jambunathan K
2013-02-18 14:58 ` Tassilo Horn
2013-02-18 15:00 ` Didier Verna
2013-02-18 15:09 ` Alan Mackenzie
2013-02-18 15:41 ` Thierry Volpiatto
2013-02-18 16:15 ` Drew Adams
2013-02-18 16:26 ` Thierry Volpiatto
2013-02-18 16:40 ` Drew Adams
2013-02-18 16:29 ` Lawrence Mitchell
2013-02-18 15:42 ` Tassilo Horn
2013-02-18 16:19 ` Didier Verna [this message]
2013-02-19 1:40 ` Glenn Morris
2013-02-19 15:25 ` Richard Stallman
2013-02-19 17:28 ` Stefan Monnier
2013-02-19 23:29 ` Richard Stallman
2013-02-20 0:08 ` Stefan Monnier
2013-02-20 8:09 ` Tassilo Horn
2013-02-20 14:05 ` Stefan Monnier
2013-02-20 21:36 ` Richard Stallman
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=muxhal9h9xd.fsf@Uzeb.i-did-not-set--mail-host-address--so-tickle-me \
--to=didier@didierverna.net \
--cc=acm@muc.de \
--cc=emacs-devel@gnu.org \
--cc=kjambunathan@gmail.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).