[Top][All Lists]

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

Re: Divide by zero or how to overload a function

From: rm
Subject: Re: Divide by zero or how to overload a function
Date: Mon, 22 Oct 2001 18:16:57 +0200
User-agent: Mutt/1.0.1i

On Mon, Oct 22, 2001 at 12:08:45PM -0400, Brett Viren wrote:
> Hi,
> 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)
> widget.
> 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 "/"?

What about the following:
  guile> (define the-real-/ /)
  guile> (the-real-/ 25 5)
  guile> (define / (lambda (a b) (+ 1 (the-real-/ a b))))
  guile> (/ 25 5)

 Ralf Mattes

> Or is there any other good way to turn a divide by zero into a zero?
> Thanks,
> -Brett.
> _______________________________________________
> Guile-user mailing list
> address@hidden

reply via email to

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