bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#18059: 24.3.92; defvar and special variables


From: Noam Postavsky
Subject: bug#18059: 24.3.92; defvar and special variables
Date: Sat, 10 Feb 2018 19:38:41 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux)

Michael Heerdegen <michael_heerdegen@web.de> writes:

> After reading this and thinking about it, I'm confused now what the
> extent of `defvar' without a specified value is.
>
> In the case of a file, does it mean that the variable is considered
> special for the rest of the file, or for the whole file?

The rest of the file, I believe.  AFAIK, both interpretation and
compilation are 1-pass.

> ;; -*- lexical-binding: t -*-
>
> (defvar testfun nil)
>
> (let ((x 1) f g)
>   (defvar x)
>   (setq testfun (lambda () x)))
>
> (funcall testfun)

> [...] you get 1

> I don't really see the connection to a `let' block:
> the defvar is in a let block, but the variable is
> not treated as special in the block.

Yes, but the let-binding happened before the defvar.  

> ;; -*- lexical-binding: t -*-
>
> (defvar testfun nil)
>
> (progn
>   (defvar x)
>   (let ((x 1) f g)
>     (setq testfun (lambda () x))))
>
> (funcall testfun)

> [...] gives you an error.  

> [the defvar is] outside, but the variable is treated as special
> (though the extent is surely not limited to any `let' block).

Right, because the defvar is not inside any let-block, so it applies to
the rest of the file.

Compare

    ;; -*- lexical-binding: t -*-

    (progn
      (defvar x))

    (let ((x 1))
      (setq testfun (lambda () x)))

    (message "%S" (funcall testfun))

vs

    ;; -*- lexical-binding: t -*-

    (let (_)
      (defvar x))

    (let ((x 1))
      (setq testfun (lambda () x)))

    (message "%S" (funcall testfun))

I noticed doing (let () (defvar x)) seems to be the same as (progn
(defvar x)), which may be a bug.





reply via email to

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