[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: |
Robert A. Uhl |
Subject: |
Re: Divide by zero or how to overload a function |
Date: |
Mon, 22 Oct 2001 11:17:39 -0600 |
User-agent: |
Mutt/1.2.5i |
On Mon, Oct 22, 2001 at 12:08:45PM -0400, Brett Viren wrote:
>
> 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 "/"?
Couldn't let or something like that work? To create your function,
use let to create an environment in which real-divide is bound to
/, then return your divide function (which references real-divide),
which you then bind / to. The following code is very probably wrong
wrong wrong, as my scheme skills are lacking:
(set! / (let ((real-divide /)) (lambda your code here)))
Apologies to those who do well with scheme. And apologies if my
understanding of let is lacking.
--
Robert Uhl <address@hidden>
The Bible is not my Book and Christianity is not my religion. I could
never give assent to the long complicated statements of Christian dogma.
--Abraham Lincoln, tyrant
Re: Divide by zero or how to overload a function,
Robert A. Uhl <=