Re: (warn) isn't doing what I expect it to



Nathan Baum <nathan_baum@xxxxxxxxxxxxxx> writes:

> Edi Weitz wrote:
> > On Mon, 29 Aug 2005 23:13:44 +0100, Nathan Baum <nathan_baum@xxxxxxxxxxxxxx> wrote:
> >
> >>So HANDLER-CASE unwinds the dynamic environments before executing
> >>its forms. Most unexpected. It works if I use HANDLER-BIND.
> > Why unexpected? That exactly is the difference between HANDLER-CASE
> > and HANDLER-BIND.
>
> But I didn't expect that to be the difference. ;)

Because you read that the effect would be otherwise in some authoritative
place that was wrong? Or because you just made up an effect that you hoped
it would happen and wishing didn't make it so? Or because you mis-read what
someone else had written? I'm always curious what the source of radical
misconceptions is, and especially so in this case since it's an area about
which there is rampant confusion. I'm not trying to embarrass you--this
is just random statistics-taking on my part. Feel free to reply in private
mail if you'd like.

> In this instance, yes. My real code isn't only muffling the warning;
> it's displaying it in a nice way first. I just want to stop the
> implementation-defined warning output being produced (but of course I
> don't want to prevent further processing where the warning was
> signalled).
>
> I'll some kind of macro, perhaps like
>
> (warning-case
> (do-something)
> (missing-function (c)
> (format t "WARNING: Function ~A not found"
> (missing-function-function c))))
>
> if it turns out I need to do this again.

Assuming there is a MISSING-FUNCTION warning that is a subclass of
WARNING (and there is none such defined by CL), you should be able
to do:

(handler-bind (((and warning (not missing-function))
#'muffle-warning))
(do-something))

That is, rather than explicitly force output for something that was
going to output anyway, just head off the output for things you don't
want output about...

The idea of writing something to do FORMAT such as you suggest is
wrong for several reasons.

- You're outputing to *STANDARD-OUTPUT*, which is not where
warnings are ordinarily meant to go--it gets them mixed up
in output for programs.

- You're printing the word "WARNING" onto the stream rather than
leaving it to the system to use the appropriate notation for the
particular implementation.

- You're bypassing the system's natural desire to end your warning
text with a newline. You're not required to put a newline into
a warning or error message, but the system is supposed to supply
one.

- You're printing the error message with ~A about the name of a
function, hiding appropriate escaping that should be done.
That is, if the function's name is |FOO\\xyz| you're going to
output FOO\xyz which will confuse people about whether the \
is part of the name or just an escape for the x that follows.
If you use ~S instead, the name will output as FOO\\\x\y\z or
|FOO\\xyz| or FOO\\|xyz| any of which may look ugly, but are
parseable by Lisp.

- You're writing code that does (format ...) in order to keep code
from executing that intends to do (format ...), which is just
repeated effort.

You might want to read the section on the condition system in ANSI CL
(e.g., via CLHS):
http://www.lispworks.com/documentation/HyperSpec/Body/09_a.htm
or CLTL2 [which is slightly out-of-date and therefore wrong in a few
technical details but has a more introductory-style presentation you
might find friendly to get started]
http://cltl2.lisp.se/cltl/clm/node312.html#SECTION003300000000000000000
and/or you might want to read my two papers on conditions
http://www.nhplace.com/kent/Papers/Exceptional-Situations-1990.html
http://www.nhplace.com/kent/Papers/Condition-Handling-2001.html
[These two papers cover different issues, so it's worth reading both.]
.



Relevant Pages

  • Re: Help with paper.
    ... Resistance is futile [said some robot in a piece of fiction]. ... Was I supposed to read from a collection of the papers that can't get ...
    (sci.physics)
  • The One Panel Case Files -- Panel 202
    ... the web and not in the papers, ... WARNING: this guy also has political cartoons, ... under your skin. ...
    (rec.arts.comics.strips)