I've started working on a port of SchemeUnit
(http://schematics.sourceforge.net/schemeunit.html) for SISC. My
first step is to look at which features of MzScheme that SchemeUnit
uses that I can implement in SISC.
SchemeUnit uses the WITH-HANDLERS form of MzScheme
(http://download.plt-scheme.org/doc/299.100/html/mzscheme/mzscheme-Z-H-6.html#node_idx_868).
WITH-HANDLERS allows you to choose which exceptions to catch, by
supplying a predicate to test whether the exception is one that you're
interested in.
(with-handlers ((exn:fail:contract:divide-by-zero?
(lambda (exn) +inf.0)))
(/ n d))
Now, an implementation of WITH-HANDLERS itself looks pretty easy.
A user could write predicates that work with SISC's existing
exception system:
(define (divide-by-zero? ex)
(equal? (error-message ex) "division by zero."))
However, MzScheme also allows new exception types to be created and
thrown. SchemeUnit uses this functionality, having a exception type
to indicate a test failure, and then, for example, a subtype to
indicate that the test failed because of a failed assertion.
I can think of a couple ways to implement this in SISC.
One way would be to emulate this functionality by wrapping it around
the existing SISC exception system.
For example, users could define error types and then throw them with
SISC's MAKE-ERROR, perhaps passing in the user defined exception in
the MESSAGE slot of SISC's error record.
The implementation emulating WITH-HANDLERS could look at the error
record it caught and handle it differently depending on whether the
MESSAGE slot contained a user define exception or not: pass the error
record as it is to the predicate if it didn't have a user defined
error, or pass the user defined error instead to the predicate if it
did.
This would then work with user defined error types, and with
predicates that tested for existing SISC errors, such as the
definition of DIVIDE-BY-ZERO? above.
Or, another option is we could extend SISC's exception system to
directly support user defined error types. I was curious, is there
any interest in looking into this possibility?
Andrew Wilcox
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
|