[Top][All Lists]

[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: Sun, 18 Feb 2018 17:28:26 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux)

Noam Postavsky <address@hidden> writes:

> Noam Postavsky <address@hidden> writes:
>> Stefan Monnier <address@hidden> writes:
>>>> I noticed doing (let () (defvar x)) seems to be the same as (progn
>>>> (defvar x)), which may be a bug.
>>> Both interpretations would make sense, so given the lack of
>>> documentation about the intention, we could consider it as a feature as
>>> much as a bug.
>>> Have you checked whether the behavior is the same with the
>>> byte-compiler?
>> Yes, it's the same.
> It's the same when let-binding a lexical variable, but not when binding
> a dynamic one.
>     ;; -*- lexical-binding: t -*-
>     (defvar foo-dynamic 'foo)
>     (let ((foo-dynamic 99))
>       (defvar x))
>     (let ((x 1))
>       (setq testfun (lambda () x)))
>     (message "%S" (funcall testfun))
> gives
>     Symbol’s value as variable is void: x
> when running the interpreted version, and
>     1
> when running the compiled version.

This let-block thing feels more like a bug to me, so I'm inclined to
leave it out of the manual.  I'm also not so sure about putting in
examples into the manual; the shortest and simplest I could come up with
is this, but I don't know that it's worth putting in.

    This example demonstrates the effects of using @code{defvar} without
    an initial value:

    (let ((x 'lexical))
      (defun get-lexical-x ()
    (defvar x)
    (defun get-dynamic-x ()

    (let ((x 'dynamic))
      (list (get-dynamic-x)
         @result{} (dynamic lexical)
    @end group
    @end example

Here's the patch I have in my local repo right now:

Attachment: v2-0001-Explain-more-about-defvar-foo-form-Bug-18059.patch
Description: patch

reply via email to

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