guile-user
[Top][All Lists]
Advanced

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

Re: Divide by zero or how to overload a function


From: Chris Cramer
Subject: Re: Divide by zero or how to overload a function
Date: Tue, 23 Oct 2001 00:34:30 -0500
User-agent: Mutt/1.2.5i

On Mon, Oct 22, 2001 at 02:31:55PM -0400, Brett Viren wrote:
> Although, one slightly negative thing is that after each subsequent
> reloading of the code, processing goes through the fake "/" more and
> more times in order to get to the real "/".  But, I can live with this.

One thing you could do is check to see if / has already been redefined:
(sorry, I changed your code around a bit... the letrec and set! just
felt really weird)

(if (not (closure? /))
    (set! /
        (let ((original-/ /))
            (lambda (a . l)
                (let loop ((a a) (l l))
                    (cond
                        ((null? l) a)
                        ((zero? (car l)) 0)
                        (else
                            (loop (original-/ a (car l)) (cdr l)))))))))

But it really seems to me that redefining / is the wrong way to approach
the problem. I don't know what the right way is, though.

-- 
C. Ray C. aka Christopher Cramer
address@hidden
http://www.pyro.net/~crayc/



reply via email to

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