[Top][All Lists]

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

Re: Possible defvar bug

From: Didier Verna
Subject: Re: Possible defvar bug
Date: Mon, 18 Feb 2013 17:19:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Alan Mackenzie <address@hidden> 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

> 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.
| 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

reply via email to

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