record exceptions that are supposed to use &assertion

Bug #173369 reported by Derick Eddington
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Released
Low
Abdulaziz Ghuloum

Bug Description

The R6RS says a number of exceptions raised by the record stuff are supposed to use &assertion, but currently &error is being used. I searched chapter 6 for "assertion" and I've made the below changes so things use &assertion where chapter 6 says they're supposed to. Also, I improved some of the exception messages, I made the opaque and sealed tests test for boolean equivalence per the report, and I removed the (eqv? name (rtd-name rtd)) because the report does not say to do that test and the returned nongenerative record type is always the first one which always prints the name of the first one anyways.

=== modified file 'scheme/ikarus.records.procedural.ss'
--- scheme/ikarus.records.procedural.ss 2007-11-21 06:39:31 +0000
+++ scheme/ikarus.records.procedural.ss 2007-12-02 01:26:08 +0000
@@ -55,7 +55,7 @@

   (define (record-rtd x)
     (define (err x)
- (error 'record-rtd "not a record" x))
+ (assertion-violation 'record-rtd "not a record, or record is opaque" x))
     (if ($struct? x)
         (let ([rtd ($struct-rtd x)])
           (if (rtd? rtd)
@@ -144,7 +144,7 @@
         (cond
           [(rtd? parent)
            (when (rtd-sealed? parent)
- (error who "cannot extend sealed parent" parent))
+ (assertion-violation who "cannot extend sealed parent" parent))
            (make-rtd-aux name parent uid sealed?
              (or opaque? (rtd-opaque? parent))
              (rtd-size parent)
@@ -153,6 +153,9 @@
            (make-rtd-aux name parent uid sealed? opaque? 0
              (convert-fields fields))]
           [else (error who "not a valid parent" parent)])))
+ (define (boolean-equivalent? x y)
+ (or (and (not x) (not y))
+ (and x y)))
     (define (same-fields-as-rtd? fields rtd)
       (let* ([fv (rtd-fields rtd)]
              [n (vector-length fv)])
@@ -179,12 +182,13 @@
           [(lookup-rtd uid) =>
            (lambda (rtd)
              (unless
- (and (eqv? name (rtd-name rtd))
- (eqv? parent (rtd-parent rtd))
- (eqv? sealed? (rtd-sealed? rtd))
- (eqv? opaque? (rtd-opaque? rtd))
+ (and (eqv? parent (rtd-parent rtd))
+ (boolean-equivalent? sealed? (rtd-sealed? rtd))
+ (boolean-equivalent? opaque? (rtd-opaque? rtd))
                     (same-fields-as-rtd? fields rtd))
- (error who "invalid arguments"))
+ (assertion-violation who
+ "arguments not equivalent to nongenerative record type with the same uid"
+ parent sealed? opaque? fields))
              rtd)]
           [else
            (let ([rtd (generate-rtd name parent uid sealed? opaque? fields)])
@@ -195,9 +199,9 @@
         (unless (symbol? name)
           (error who "not a valid record type name" name))
         (unless (boolean? sealed?)
- (error who "not a valid sealed? argument" sealed?))
+ (error who "not a valid sealed argument" sealed?))
         (unless (boolean? opaque?)
- (error who "not a valid opaque? argument" opaque?))
+ (error who "not a valid opaque argument" opaque?))
         (cond
           [(symbol? uid)
            (make-nongenerative-rtd name parent uid sealed? opaque? fields)]
@@ -357,7 +361,7 @@
         (unless (fx< i sz)
           (error who "not a valid index" k))
         (unless (car (vector-ref (rtd-fields rtd) k))
- (error who "field is not mutable" k rtd))
+ (assertion-violation who "field is not mutable" k rtd))
         (let ([a-record-mutator
                (lambda (x v)
                  (cond

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 173369] record exceptions that are supposed to use &assertion

On Dec 1, 2007, at 8:50 PM, Derick Eddington wrote:

> Public bug reported:
>
> The R6RS says a number of exceptions raised by the record stuff are
> supposed to use &assertion, but currently &error is being used.

I think this applies to almost all the errors that Ikarus currently
raises.
I will fix all of them at once at some time. Not today.

> I
> searched chapter 6 for "assertion" and I've made the below changes so
> things use &assertion where chapter 6 says they're supposed to.
> Also, I
> improved some of the exception messages,

OK. Thanks.

> I made the opaque and sealed
> tests test for boolean equivalence per the report,

eqv? and your boolean-equivalent? both return the same thing for
boolean values.
I don't see why you're making this change.

> and I removed the
> (eqv? name (rtd-name rtd)) because the report does not say to do that
> test and the returned nongenerative record type is always the first
> one
> which always prints the name of the first one anyways.

I don't know if this was intentional or by mistake. Will do as the
report says anyways.

Aziz,,,

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Will fix the assertion violations at some later time.

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → Low
status: New → Confirmed
Revision history for this message
Derick Eddington (derick-eddington) wrote :

re: boolean-equivalent?

The report paragraph about make-record-type-descriptor being "called twice with the same uid symbol" says the sealed? and opaque? arguments are to be compared as "both #f or both true" and (eqv? "true" 'true) doesn't work. Not sure why the report allows true instead of #t here ... consistent with the rest of booleans in Scheme I suppose.

Also, I place the above patch in the public domain and I waive all copyright claims to it; just in case...
I'll not post patches anymore.

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 173369] Re: record exceptions that are supposed to use &assertion

> The report paragraph about make-record-type-descriptor being "called
> twice with the same uid symbol" says the sealed? and opaque? arguments
> are to be compared as "both #f or both true" and (eqv? "true" 'true)
> doesn't work. Not sure why the report allows true instead of #t here
> ... consistent with the rest of booleans in Scheme I suppose.

Actually, from the report:
   The sealed? flag must be a boolean. [...]

   The opaque? flag must be a boolean. [...]

So, eqv? is okay since we do an error check earlier.

Revision history for this message
Derick Eddington (derick-eddington) wrote :

JTMI, I think another exception message in ikarus.records.procedural.ss could be made more helpful:
line 186, something more informative like:
"arguments not equivalent to nongenerative record type with the same uid"

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed all(?) incorrect uses of error in revision 1248.

Changed in ikarus:
status: Confirmed → Fix Committed
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

This bug report is about to be closed as the fix comitted
previously will be incorporated in the next 0.0.3 release of
Ikarus Scheme, scheduled for January 31, 2008. A release
candidate tarball is available for download from:
http://www.cs.indiana.edu/~aghuloum/ikarus/ikarus-0.0.3-rc1.tar.gz
Please do test it if you have the time and report any issues
you might encounter. Thank you very much for your support.
(Sorry for the duplicates; I'm updating every open bug.)

Changed in ikarus:
milestone: none → 0.0.3
Changed in ikarus:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.