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

type declarations of special bindings

    Date: Sat, 23 Jan 88 01:18:23 PST
    From: Jon L White <edsel!jonl@labrea.Stanford.EDU>

    re: In the following example, does the fixnum declaration apply to the
	inner reference to X (in the setq)?
	  (let ((X 17))
	    (declare (special X) (fixnum X))
	    (let ((X 'local))
		(declare (special X))
		(setq X (foo)))))

    CLtL, p 158 says that type declarations affect the binding "and specifies
    that the variable[s] mentioned will take on values only of the specified
    type".  The inner reference is to the variable bound specially, not to
    the one bound locally, so it is the same variable whose binding was
    declared fixnum.  Hence, in theory, it should be as if the form
	    (setq X (foo))
    were written as
	    (setq X (the fixnum (foo)))
    but I suspect very few, if any, compilers actually make this leap of type 

    -- JonL --

I agree with your interpretation.

I don't think it's much of a leap of inferencing, at least not for
any way that I would think to write a compiler.  Most compilers
create some sort of "VAR" structure where information about a
variable is stored.  After all, code generation has to make exactly
the same leap of inferencing, to figure out just where to get the
variable *from*.

But I have no comment as to whether existing compilers actually
do or do not (as you suggest) actually do anything with this.
My point is just that it isn't a burden for any well-designed

Note that there's no actual obligation that the compiler generate
code to enforce it; there's just an obligation that the user not
write code which violates it.  (I don't see any way a compiler
could handle this in an *illegal* way.)