[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: |
Marius Vollmer |
Subject: |
Re: Divide by zero or how to overload a function |
Date: |
22 Oct 2001 23:41:11 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.102 |
Brett Viren <address@hidden> writes:
> 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....
You could also create a new module and evaluate the user's code there.
The new module could shadow the `/' binding. This will work nicely
even when the module code is loaded multiple times.
(define (user-module-with-funny-math)
:use-module ((guile) :select ((/ . real-/))))
(define (/ . args)
(catch 'numerical-overflow
(lambda () (apply real-/ args))
(lambda throw-args 0)))
Actually, I think it is better to use a new name for a division
operator that returns zero for zero divisors. Maybe `//'?
Re: Divide by zero or how to overload a function, Robert A. Uhl, 2001/10/22