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
> > 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
> 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