[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Need for (declare (ignorable ...))
Date: Fri, 7 Mar 86 13:05:09 EST
From: Jonathan A Rees <JAR@MC.LCS.MIT.EDU>
Common Lisp (and in fact, every language that has variables) needs a
(DECLARE (IGNORABLE ...)) in addition to (DECLARE (IGNORE ...)). The
meaning of (DECLARE (IGNORABLE X)) is: the variable X might or might not
be used, and I don't want the compiler to generate a warning in either
case.
I agree.
There is no way to simulate this feature in Common Lisp. If there is no
such declaration, and X isn't used, then I get a warning message X bound
but not used; if I use (DECLARE (IGNORE X)), and X is used, then I get a
warning message saying that X was declared ignored but in fact was used.
I wouldn't want to change either of these features of Common Lisp
compilers.
(defun foo (x)
x
'bar)
Is one possible workaround, but it doesn't make it obvious what the
intent is. In Symbolics Common Lisp, you can do
(defun foo (x)
(ignore x)
'bar)
which is a common cliche because the IGNORABLE declaration doesn't
exist.
The IGNORABLE declaration is needed for applications where code is
automatically generated, say, by a macro or a compiler. A macro,
especially, is not in a good position to know whether a variable is
being referenced. A sledgehammer like a code traversal tool shouldn't
be required for this simple application. It has been in T (Yale Scheme)
since 1981, and has proved very useful.
Have other people suffered from this lack, or do I just write
particularly perverse macros?
Jonathan Rees