Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Warnings?

5 views
Skip to first unread message

Jrm

unread,
Jul 17, 1998, 3:00:00 AM7/17/98
to
I've worked with Lisps in which this is actually the
way to fool the compiler into thinking that you have
`used' the variable (and thus supress unused variable
warnings.)

Rainer Joswig wrote in message ...
>Given a function:
>
>(defun baz ()
> *foo*
> *bar*)
>
>Should the compiler warn that *foo* is not being used?

Paul Dietz

unread,
Jul 17, 1998, 3:00:00 AM7/17/98
to
Rainer Joswig wrote:
>
> Given a function:
>
> (defun baz ()
> *foo*
> *bar*)
>
> Should the compiler warn that *foo* is not being used?


I hope not. I write macros that introduce temporaries
like this:

(let ((temp ...))
temp
...)

so that the compiler does not issue spurious warnings
if temp is not actually used in the rest of the let body.
This works under Franz's ACL.

Paul

Rainer Joswig

unread,
Jul 18, 1998, 3:00:00 AM7/18/98
to

Kent M Pitman

unread,
Jul 18, 1998, 3:00:00 AM7/18/98
to
"Jrm" <emer...@eval-apply.com> writes:

> I've worked with Lisps in which this is actually the
> way to fool the compiler into thinking that you have
> `used' the variable (and thus supress unused variable
> warnings.)

Yeah, still to this day there are places I do
(defun foo (x)
x ; ignored
1)
because nearly every lisp knows this means not to warn about X and some
deviant lisps do not know about the IGNORE declaration. I also sometimes
do (dotimes (i 5)
(progn i) ;ignored - can't use just "i" because of tagbody in dotimes
(print 'foo))
but notice this is -usually- with lexicals that one does this. For an
example involving specials, you have to work harder, but I offer one at
the end of this message.

> Rainer Joswig wrote in message ...

The important thing is that the warnings be possible to turn off.
Unreachable code or lost values is the inevitable result of automatic
programming (which includes macros). To forbid it or even make
serious noise about it is to cripple any mechanical help in
program-writing. I used to write macros that resulted in

(OR)
(OR foo)
(COND (T ...))
(COND (T ...) (FOO ...))

and stuff like that and the compiler used to warn. I ended up having
code that said:

`(OR '$MAKE-COMPILER-HAPPY$ ,@x)

just to avoid the warning, but this in fact made the program slower
a lot of the time. This is no way to make programmers work. We define
degenerate cases because they are meaningful and while it's fine to
provide a mode where odd code gets flagged for easy debugging, one
doesn't want warnings about these things to get in the way of REAL
warnings, such as the famous one from Symbolics Genera, which went
approximately like:

For Macro FOO:
The macro FOO was previously assumed to be a function.
You will indubitably lose.

For example, the function BAZ in Rainer's mail could result from:

(defmacro frob (&rest forms)
`(let ((*frob-on* t))
*default-frob-value*
,@forms))

(defun baz () (frob *foo*))

The last thing you want to have to do is document the macro expansion
so that the user is required to do:

(defun baz () (declare (ignore *default-frob-value*)) (frob *foo*))

which would be even uglier!


Sunil Mishra

unread,
Jul 18, 1998, 3:00:00 AM7/18/98
to
Kent M Pitman <pit...@world.std.com> writes:

> "Jrm" <emer...@eval-apply.com> writes:
>
> > I've worked with Lisps in which this is actually the
> > way to fool the compiler into thinking that you have
> > `used' the variable (and thus supress unused variable
> > warnings.)
>
> Yeah, still to this day there are places I do
> (defun foo (x)
> x ; ignored
> 1)

I have run into this more times than I can count, and each time I've wished
there were an ignorable declaration. Can't imagine it being *that* hard to
do, especially since the compiler knows when variables are not used.

Sunil

Erik Naggum

unread,
Jul 18, 1998, 3:00:00 AM7/18/98
to
* Paul Dietz

| I hope not. I write macros that introduce temporaries like this:
|
| (let ((temp ...))
| temp
| ...)
|
| so that the compiler does not issue spurious warnings if temp is not
| actually used in the rest of the let body. This works under Franz's ACL.

ANSI Common Lisp provides an IGNORABLE declaration that should warn
neither when the variable is used nor when not used. (it is almost as
annoying to have to declare unused variables in MULTIPLE-VALUE-BIND and
such as it is to have a compiler whine that you lied to it about not
using one of them.) Franz Inc's Allegro Common Lisp [for Unix] has
"always" had an EXCL::IGNORE-IF-UNUSED declaration that behaves exactly
the same as IGNORABLE is specified to do, and ACL still uses it in the
expansion of some macros that inquisitive users may run into, which is
why they document it. (4.3 User Guide, Appendix A, item 300.)

while I tend to think the declaration syntax in CL is a bit on the
verbose and cumbersome side, I still prefer them to hacks like the above.
I'd be inclined to remove a line like that if I were to review such code.

[pet peeve alert] ... and isn't it about time to demand ANSI CL semantics
in the Common Lisps we use?

#:Erik
--
http://www.naggum.no/spam.html is about my spam protection scheme and how
to guarantee that you reach me. in brief: if you reply to a news article
of mine, be sure to include an In-Reply-To or References header with the
message-ID of that message in it. otherwise, you need to read that page.

Paul Dietz

unread,
Jul 18, 1998, 3:00:00 AM7/18/98
to
Erik Naggum wrote:

> ANSI Common Lisp provides an IGNORABLE declaration that should warn
> neither when the variable is used nor when not used.

I didn't realize. Thanks.

Paul

Kent M Pitman

unread,
Jul 19, 1998, 3:00:00 AM7/19/98
to
Sunil Mishra <smi...@cleon.cc.gatech.edu> writes:

Well, Common Lisp does specify both IGNORE (must be ignored) and
IGNORABLE (may but does not have to be ignored) declarations, so
compilers these days are supposed to support it. But the art of
writing robust code is a tricky one, so one can't always count on them
being there even though they're required.

0 new messages