Minor conditions cleanup
Carl Gay <[email protected]> Sun, 11 May 2014 15:53:25 -0400
| Newsgroups | gmane.comp.lang.dylan.gwydion.devel |
|---|---|
| Message-ID | <CALekcH0RmzOLn6xZoa+oCN7Qda1e8ZREOjGSEywaZYqqLaVnNA@mail.gmail.com> |
--===============1932863446==
Content-Type: multipart/alternative; boundary=089e013c647010049904f9252f39
--089e013c647010049904f9252f39
Content-Type: text/plain; charset=UTF-8
I'd like to make a minor cleanup to the condition classes signaled for
collections code. Please let me know if you object to these changes or if
you would suggest specific changes. If there are no objections in
principle I can send a patch for review to the list.
Summary:
- All collection access that involves a bad key of any kind will signal
a subclass of <key-error> instead of the current disjoint set of
conditions: <not-found-error>, <invalid-index-error>,
<subscript-out-of-bounds-error>, and <empty-collection-error>. This
includes
- invalid index for sequence
- invalid number of array subscripts (rank errors)
- reduce1, pop, first, second, last, etc on an empty (or too small)
collection
- element(<set>, value) if value not present
This would *not* cover, for example, element(<string-table>, <integer>) and
other type errors, as it looks to me like that would involve inserting
run-time checks that would slow down access. (I only took a very brief
look at this. I suspect these cases currently signal <type-error>.)
The main point is to have one shared condition class for invalid collection
accesses. I personally don't see a lot of advantage in keeping the
existing condition classes around as subclasses of <key-error> (except
perhaps <subscript-error>, see diff), but I'd like to hear what others
think.
-Carl
diff --git a/sources/dylan/collection.dylan b/sources/dylan/collection.dylan
index 7d0745c..dd1c0ba 100644
--- a/sources/dylan/collection.dylan
+++ b/sources/dylan/collection.dylan
@@ -122,24 +122,18 @@ define open generic remove!
=> (possibly-new-coll :: <collection>);
-// Access conditions
-// TODO: need a better hierarchy than this.
+// Collection access conditions
define class <key-test-error> (<simple-error>) end;
-define class <not-found-error> (<simple-error>) end;
-
-// define class <key-not-found-error> (<not-found-error>) end;
-
-// define class <value-not-found-error> (<not-found-error>) end;
-
-define class <invalid-index-error> (<not-found-error>) end;
-
-define class <subscript-out-of-bounds-error> (<invalid-index-error>) end;
-
define class <iteration-error> (<simple-error>) end;
-define class <empty-collection-error> (<simple-error>) end;
+// For any attempt to access an invalid collection key.
+// Note that <set> keys are the values themselves.
+define class <key-error> (<simple-error>) end;
+
+// Number of subscripts does not match the array rank.
+define class <subscript-error> (<key-error>) end;
--089e013c647010049904f9252f39
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>I'd like to make a minor cleanup to the condition=
classes signaled for collections code. =C2=A0Please let me know if you obj=
ect to these changes or if you would suggest specific changes. =C2=A0If the=
re are no objections in principle I can send a patch for review to the list=
.</div>
<div><br></div><div>Summary:</div><div><ul><li>All collection access that i=
nvolves a bad key of any kind will signal a subclass of <key-error> i=
nstead of the current disjoint set of conditions: <not-found-error>, =
<invalid-index-error>, <subscript-out-of-bounds-error>, and <=
;empty-collection-error>. =C2=A0This includes<br>
</li><ul><li>invalid index for sequence</li><li>invalid number of array sub=
scripts (rank errors)</li><li>reduce1, pop, first, second, last, etc on an =
empty (or too small) collection</li><li>element(<set>, value) if valu=
e not present</li>
</ul></ul>This would <b>not</b> cover, for example, element(<string-tabl=
e>, <integer>) and other type errors, as it looks to me like that =
would involve inserting run-time checks that would slow down access. =C2=A0=
(I only took a very brief look at this. =C2=A0I suspect these cases current=
ly signal <type-error>.)<br>
</div><div><br></div><div>The main point is to have one shared condition cl=
ass for invalid collection accesses. =C2=A0I personally don't see a lot=
of advantage in keeping the existing condition classes around as subclasse=
s of <key-error> (except perhaps <subscript-error>, see diff), =
but I'd like to hear what others think.</div>
<div><br></div><div>-Carl</div><div>=C2=A0<br></div><div><br></div><div><br=
></div><div>diff --git a/sources/dylan/collection.dylan b/sources/dylan/col=
lection.dylan</div><div>index 7d0745c..dd1c0ba 100644</div><div>--- a/sourc=
es/dylan/collection.dylan</div>
<div>+++ b/sources/dylan/collection.dylan</div><div>@@ -122,24 +122,18 @@ d=
efine open generic remove!</div><div>=C2=A0 =3D> (possibly-new-coll :: &=
lt;collection>);</div><div>=C2=A0</div><div>=C2=A0</div><div>-// Access =
conditions</div>
<div>-// TODO: need a better hierarchy than this.</div><div>+// Collection =
access conditions</div><div>=C2=A0</div><div>=C2=A0define class <key-tes=
t-error> (<simple-error>) end;</div><div>=C2=A0</div><div>-define =
class <not-found-error> (<simple-error>) end;</div>
<div>-</div><div>-// define class <key-not-found-error> (<not-foun=
d-error>) end;</div><div>-</div><div>-// define class <value-not-foun=
d-error> (<not-found-error>) end;</div><div>-</div><div>-define cl=
ass <invalid-index-error> (<not-found-error>) end;</div>
<div>-</div><div>-define class <subscript-out-of-bounds-error> (<i=
nvalid-index-error>) end;</div><div>-</div><div>=C2=A0define class <i=
teration-error> (<simple-error>) end;</div><div>=C2=A0</div><div>-=
define class <empty-collection-error> (<simple-error>) end;</di=
v>
<div>+// For any attempt to access an invalid collection key.</div><div>+//=
Note that <set> keys are the values themselves.</div><div>+define cl=
ass <key-error> (<simple-error>) end;</div><div>+</div><div>
+// Number of subscripts does not match the array rank.</div><div>+define c=
lass <subscript-error> (<key-error>) end;</div><div>=C2=A0</div=
><div>=C2=A0</div><div>=C2=A0</div><div><br></div></div>
--089e013c647010049904f9252f39--
--===============1932863446==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
hackers mailing list
[email protected]
https://lists.opendylan.org/mailman/listinfo/hackers
--===============1932863446==--