This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Emacs Lisp undefined variables [was: GSOC | Extending Common Lisp support]
On May 20, 2012, at 8:15 PM, Per Bothner wrote:
On 05/20/2012 04:44 PM, Jamison Hope wrote:
Regarding the warnings themselves, they're due to setq calls with
previously-undeclared variables. I'm not sure whether that's supposed
to trigger a warning in ELisp, so it might be a bug, but it's
orthogonal
to your project. (Let's focus on one Lisp at a time..)
I thought about this - but IIRC Emacs also emits those warnings
when byte-compiling such code. Probably we should check newer version
of Emacs for the most recent versions of those elisp files.
Looks like you're right. I see warnings in 23.4 when I call
byte-compile-file on gnu/jemacs/testsuite/lang-test.el. There aren't
any warnings if call setq interactively (e.g. in *scratch*), though,
so I went to the Emacs Lisp manual
<http://www.gnu.org/software/emacs/manual/elisp.html> to see if it had
anything definitive to say.
I found this in section 8.2 Defining Symbols:
In Emacs Lisp, a definition is not required in order to use a symbol
as a
variable or function. Thus, you can make a symbol a global variable
with
setq, whether you define it first or not.
So it's officially legal to bind a undefined variable with setq. But
that
doesn't say that you won't see a warning if you skip the definition.
Appendix D.5 Tips for Avoiding Compiler Warnings says:
Try to avoid compiler warnings about undefined free variables, by
adding
dummy defvar definitions for these variables, like this:
(defvar foo)
Such a definition has no effect except to tell the compiler not to
warn
about uses of the variable foo in this file.
So Emacs will warn, but only when compiling, not when interpreting.
Since Kawa (almost) always compiles, it's probably not erroneous to
issue the warning even in the REPL. This, however, is a bug:
$ cat /tmp/test.el
(defvar foo)
(setq foo 3)
$ bin/kawa --elisp -C /tmp/test.el
(compiling /tmp/test.el to test)
/tmp/test.el:2:1: warning - no declaration seen for foo
--
Jamison Hope
The PTR Group
www.theptrgroup.com