Prev: WORK FROM YOUR HOME AWESOME EARNINGS NO INVESTMENT
Next: A portable LISP interpreter that includes all the major list-processing functions is described. A complete, annotated listing of the program's code, written in PASCAL, is included.
From: francogrex on 23 Jul 2010 08:58 I asked this before to be able to ignore divisions by zero and I was told this is implementation dependent (I use ECL 8.12); but can't I at least with a certain trick/code that is implementation independent ignore those or assign them a certain value when the division by zero occurs? I know with (setf * debug-io* nil) I can deactivate the debugger but by doing that when errors are encountered my lisp system exits abruptly, while what I want is to ignore those errors and let the computation proceed (I have a statistical procedure with iterations that sometimes have (/ x 0) infinite values encountered but that should not stop the computations or the return of the final result.
From: Tamas K Papp on 23 Jul 2010 11:05 On Fri, 23 Jul 2010 14:58:44 +0200, francogrex wrote: > I asked this before to be able to ignore divisions by zero and I was > told this is implementation dependent (I use ECL 8.12); but can't I at > least with a certain trick/code that is implementation independent > ignore those or assign them a certain value when the division by zero > occurs? I know with (setf * debug-io* nil) I can deactivate the debugger > but by doing that when errors are encountered my lisp system exits > abruptly, while what I want is to ignore those errors and let the > computation proceed (I have a statistical procedure with iterations that > sometimes have (/ x 0) infinite values encountered but that should not > stop the computations or the return of the final result. Just handle the condition. Eg (defun my/ (a b &optional (error-value 42)) (handler-case (/ a b) (division-by-zero () error-value))) CL-USER> (my/ 4 2) 2 CL-USER> (my/ 4 0) 42 Read http://www.gigamonkeys.com/book/beyond-exception-handling-conditions-and-restarts.html Best, Tamas
From: Pillsy on 23 Jul 2010 12:41 On Jul 23, 11:05 am, Tamas K Papp <tkp...(a)gmail.com> wrote: > On Fri, 23 Jul 2010 14:58:44 +0200, francogrex wrote: > > I asked this before to be able to ignore divisions by zero and I was > > told this is implementation dependent (I use ECL 8.12); but can't I at > > least with a certain trick/code that is implementation independent > > ignore those or assign them a certain value when the division by zero > > occurs? [...] > Just handle the condition. Eg > (defun my/ (a b &optional (error-value 42)) > (handler-case (/ a b) > (division-by-zero () error-value))) This is a good answer, but there's one gotcha: behavior of division by zero is unspecified. If you're being dropped into ECL's debugger, it's very likely that some error is being signaled, but it's not necessarily the case that the error in question is an instance of DIVISION-BY-ZERO. If it's some other kind of condition (the CLHS suggests ARITHMETIC-ERROR as an alternative) then you'll obviously need to use that error in the HANDLER-CASE expression. However, once you're in the debugger, it should be pretty straightforward to figure out what sort of error was being signaled. Cheers, Pillsy
From: Robert Dodier on 27 Jul 2010 11:45
On Jul 23, 6:58 am, francogrex <fra...(a)grex.org> wrote: > implementation dependent (I use ECL 8.12); > computation proceed (I have a statistical > procedure with iterations that sometimes have > (/ x 0) infinite values encountered If I remember correctly ECL can work with IEEE 754 floating point special values. There is probably some flag. You might ask on the ECL mailing list or try searching their documentation. Be that as it may, it won't affect integer division, I'm pretty sure. So you'll have to work with floats to take advantage of it. best Robert Dodier |