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

Default scope of references

    Date: 29 Oct 1985 18:09:05 EST (Tue)
    From: Dan Hoey <hoey@nrl-aic.ARPA>
				    (SETQ FOO VAL))
			     (SET-FOO NIL)))
(eval *test-1*)
==> NIL
==> NIL
			     (DEFUN GET-FOO ()
(eval *test-1*)
==> NIL
==> NIL
    in the absence of (PROCLAIM (SPECIAL FOO)), I somehow expected that
    (EVAL *TEST-1*) and (EVAL *TEST-2*) would each tell me that I was
    accessing a variable that was neither declared special nor lexically
    bound.  According to CLtL, however, ``The general rule is that if the
    symbol occurs textually within a program construct that creates a
    *binding* for a variable of the same name, then the reference is to the
    variable specified by the binding; if no such program construct
    textually contains the reference, then it is taken to refer to the
    special variable of that name.'' [p. 55]  Thus these forms are
    supposedly legally evaluable.  Is this what was intended?  
    evaluation of these forms be or signal an error?  
						      I would certainly
    hope that the answer is the same for both tests.
It is.

			     (DEFUN LEX-TEST ()
				    (LET ((FOO T))
					 (SET-FOO NIL)
(eval *test-3*)
==> T
==> NIL

(eval *test-4*)
==> T
==> NIL

I believe the "best" alternative is what VAX/NIL does; namely
give a warning like the compiler.  (It would be best if it
did it only once for a given form).  However, this might be
unpopular with users if this warning interferes with their

Of course, the real conclusion to draw from this is to
use the compiler.  Most compilers give you a lot of
static error checking that you won't see interpreted.
For example, if your compiler does wrong-number-of-args
checking, it will check the number of arguments even on
parts of your function that are only called once in a blue