Re: Global lexical variables?
- From: Kaz Kylheku <kkylheku@xxxxxxxxx>
- Date: Fri, 31 Oct 2008 00:54:52 +0000 (UTC)
On 2008-10-30, Russell Wallace <russell.wallace@xxxxxxxxx> wrote:
On Oct 30, 8:42 pm, Kaz Kylheku <kkylh...@xxxxxxxxx> wrote:
The ``it'' that CLISP is not approving of here is that you are trying
to use an undefined variable. This is not well-defined behavior in Lisp.
But I did define it:
(defvar clauses-table
(make-hash-table
:test 'equal))
Doesn't that count as a definition?
It does. I see now that it's only a compiler warning you are getting, while
compiling a particular function.
This means that the definition has not been seen at the time when the compiler
is processing the function.
If the definition is in another file, it means that the file hasn't been
loaded yet.
If the definition is in the same file, the warning means that it's later in the
file than the reference. Thus at the point of reference, the variable isn't
known yet.
The compiler is then only guessing that this free variable will later be
defined as special, and is compiling the reference that way.
A diagnostic is useful, because the compiler is guessing. Maybe you didn't
intend for the reference to be a special variable. Suppose you made this
mistake:
(defun my-func ()
foo)
(define-symbol-macro foo ...) ;; oops, later than reference
Right?
You will run into this error when you have a program made of several modules,
which define some special variables, and there is a circular dependency: module
A uses B's global variable, and B uses A's global variable.
In both possible orders, someone is compiled without the DEFVAR.
One way out of that is to put important global variables into a separate file
dedicated to global variables.
Also, DEFVAR with no value can be used as a forward reference in resolving
these situations. It will ensure that the variable exists, without changing its
value.
.
- References:
- Global lexical variables?
- From: Russell Wallace
- Re: Global lexical variables?
- From: Kaz Kylheku
- Re: Global lexical variables?
- From: Russell Wallace
- Global lexical variables?
- Prev by Date: Re: Is it a bad sign...
- Next by Date: Re: CLOS and the condition system in the CLHS
- Previous by thread: Re: Global lexical variables?
- Next by thread: CLOS and the condition system in the CLHS
- Index(es):
Relevant Pages
|