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

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

RE: Avoiding 'reference to free variable' warnings whilesplittingelisp s


From: Drew Adams
Subject: RE: Avoiding 'reference to free variable' warnings whilesplittingelisp source files
Date: Sat, 23 Mar 2013 11:23:23 -0700

> >  This form defines `foo' but does not initialize it:
> >    (defvar foo) => foo
> 
> Oops that should be "declares `foo'" since it doesn't define it.

It does (Emacs, so far) or it doesn't (Stefan).  It depends on what one means by
"defining".

The node (elisp) `Defining Variables' starts by saying what Emacs means by a
"variable definition": it "announces your intention to use a symbol as a global
variable."  That is probably pretty close to what you mean by "declaring".  It
does not mention value initialization (which is optional).

What you presumably want to point out here is that this (a vacuous `defvar')
does not define the variable's _value_.  (And it does not define the variable's
doc.)

But the Emacs approach of calling _any_ `defvar' (whether or not it defines the
value and doc) a variable _definition_ is consistent.

If you want to identify that defining with "declaring", that would be fine too.

But if you want to replace that use of "defining" with "declaring" then please
be sure to do so everywhere, and make it clear that from now on "defining"
always means declaring _and initializing_.  IOW, make clear that a `defvar' that
does not specify a value is no longer considered a vacuous "definition" etc.

To me, it is clear enough the way Emacs has always spoken: Defining means
declaring and optionally value-initializing.  That is, a variable definition
need not also give the variable a value.

  A variable definition serves three purposes.  First, it
  informs people who read the code that the symbol is _intended_
  to be used a certain way (as a variable).  Second, it informs
  the Lisp system of this, optionally supplying an initial value
  and a documentation string.  Third, it provides information to
  programming tools such as `etags', allowing them to find where
  the variable was defined.

FWIW - There are currently many, *many* occurrences of "declar" in the Elisp
manual, and *none* of them have to do with `defvar' or `defconst'.  Over 99% of
them have to do with functions and macros, and a few have to do with
"customization declarations": `defcustom', `defgroup', and `defface'.




reply via email to

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