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

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

Re: [External] : Re: Lexical vs. dynamic: small examples?


From: Stefan Monnier
Subject: Re: [External] : Re: Lexical vs. dynamic: small examples?
Date: Wed, 25 Aug 2021 19:47:20 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> This means, I've been using `defvar' to shut up the
> byte-compiler about variables not known to be defined, and
> this has actually made them dynamic?

Of course.  If the compiler says it's "not known to be defined" that
means the var isn't bound lexically (either that, or there's a bug in
the compiler), so it can only make sense if the var is
global or dynamically scoped (and both are closely related).

There exist global variables which shouldn't be dynamically scoped, but
they're rare in ELisp, mostly because of our use of namespace prefixes.

One example is the variable `pi` which holds the famous constant but we
don't want (let ((pi (get-previous-interval x))) ...) to temporarily
redefine `pi` to something unrelated.

This example is obsolete, tho: you should use `float-pi` instead of `pi`
to refer to the famous constant.


        Stefan




reply via email to

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