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: Brett Viren
Subject: Re: Divide by zero or how to overload a function
Date: Mon, 22 Oct 2001 14:23:39 -0400

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

Thanks, I tried:

(define the-real-/ /) 
(define (/ a . b)  
  (letrec ((div (lambda (a l)  
                 (cond ((equal? l '()) a) 
                       ((zero? (car l)) 0) 
                       (else  
                        (set! a (the-real-/ a (car l))) 
                        (div a (cdr l))))))) 
    (div a b))) 
 

And this works, but there are problems if this code is loaded twice
(which I can't assume my users won't do).  See my upcoming reply to
Robert for something a little better....

-Brett.



reply via email to

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