[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Divide by zero or how to overload a function

From: Brett Viren
Subject: Divide by zero or how to overload a function
Date: Mon, 22 Oct 2001 12:08:45 -0400


I have a C++ program which embeds Guile in order to let users define
Scheme functions whose results are plotted in a C++ (Gtk-- based)

Currently, if one of those functions divide by zero I catch the error
(via evaluating the function with scm_catch()) and just ignore the
result.  However, the users want their functions to return (and plot)
zero in the case of divide by zero error.

I don't want the users to have to explicitly check for divide by zero
in their Scheme functions, but rather handle it implicitly.  I thought
I could do this by writing a custom "/" Scheme function which would
just detect divide-by-zero and do the right (err, well, actually
wrong) thing and return zero.  In doing this I come across the problem
of needing to use the real "/" function but this references my
overloaded one instead and causes infinite recursion.  Is it possible
to reference the real "/" inside this overloaded "/"?

Or is there any other good way to turn a divide by zero into a zero?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]