emacs-devel
[Top][All Lists]
Advanced

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

Re: lexical binding?


From: Stefan Monnier
Subject: Re: lexical binding?
Date: Sun, 24 Oct 2021 09:32:22 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> When I "setq" variables in a defun, they are by default global,

The "in a defun" has no impact on the behavior: `setq` doesn't know
it's used from within a function.

> I don't *need* to return a list with the values to expose them to
> other functions. I can just call the various variables by name
> directly in another defun.

Not sure what you mean by "call" (which is a term usually used when you
use a function), but yes you can refer to the value of those variable by
name directly.

And if you do so, any seasoned programmer will look at your code and weep.

If you want  variable to be global, then always say it explicitly by
declaring it first with `defvar` and don't forget to use a name with
a proper namespace prefix so it doesn't collide with other
packages's variables.

Also, remember to byte-compile your code (and/or activate `flymake-mode`
when editing your Elisp code) and pay attention to the warnings you get
from it.


        Stefan




reply via email to

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