From ... Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!npeer.kpnqwest.net!reader3.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: newbie exception handling question References: <3n_m7.7829$ww1.745556@news02.tsnz.net> Mail-Copies-To: never From: Erik Naggum Message-ID: <3209103409627643@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 32 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 10 Sep 2001 09:36:50 GMT X-Complaints-To: newsmaster@Norway.EU.net X-Trace: reader3.kpnqwest.net 1000114610 193.90.207.148 (Mon, 10 Sep 2001 11:36:50 MET DST) NNTP-Posting-Date: Mon, 10 Sep 2001 11:36:50 MET DST Xref: archiver1.google.com comp.lang.lisp:16043 * Donna > of course this will produce an error/exception and that is what I want to > catch and handle gracefully, basically by giving this program a bad score > and exiting from the fitness function. If you wrap the entire function body in an ignore-errors form, it will terminate upon encountering any errors at all and return two values: a nil primary value and the error object as the secondary value, which you are free to ignore, as well. This is a quick and painless exit from a function with an error with the added bonus of returning "false". If you need more scoring "resolution" than that, perhaps the calling function can take care of it? > Now I could write functions like newrest, newfirst, etc and handle the > case when the argument is not a list, then when I find the best fit > program change newrest to rest, etc. But that seems awkward to me. I > would really rather do something more elegant. I would welcome any > suggestions, ideas, and comments. Common Lisp has a "safe mode" where all errors must be signalled. It should be the default in your environment, but can be obtained with (declaim (optimize (safety 3))) In my experience, this is where implementations differ the most in conforming, so it is hard to trust this requirement without talking to other users of the same implementation. However, if you have more knowledge than the system can intuit from what you are attempting to do, you could write your own evaluator and examine this knowledge for consistency before you get any errors.. This is not as hard as it seems. ///