[m-rev.] array.m changes to increase completeness guarantees
Peter Moulder
Peter.Moulder at infotech.monash.edu.au
Mon Aug 18 13:17:13 AEST 2003
Estimated hours taken: 0.5
library/array.m:
Improve completeness guarantees by using if-then-else's to ensure that
operations that can throw an exception are really conditional on bounds
checks.
This also allows us to call the `unsafe' (unchecked) versions directly.
Index: array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.123
diff -d -u -r1.123 library/array.m
--- library/array.m 11 Jun 2003 12:55:49 -0000 1.123
+++ library/array.m 8 Aug 2003 05:58:39 -0000
@@ -382,9 +382,14 @@
:- pragma export(array_equal(in, in), "ML_array_equal").
array_equal(Array1, Array2) :-
- array__size(Array1, Size),
- array__size(Array2, Size),
- array__equal_elements(0, Size, Array1, Array2).
+ ( if
+ array__size(Array1, Size),
+ array__size(Array2, Size)
+ then
+ array__equal_elements(0, Size, Array1, Array2)
+ else
+ fail
+ ).
:- pred array__equal_elements(int, int, array(T), array(T)).
:- mode array__equal_elements(in, in, in, in) is semidet.
@@ -656,16 +661,25 @@
Min =< Index, Index =< Max.
array__semidet_lookup(Array, Index, Item) :-
- array__in_bounds(Array, Index),
- array__lookup(Array, Index, Item).
+ ( if array__in_bounds(Array, Index) then
+ array__unsafe_lookup(Array, Index, Item)
+ else
+ fail
+ ).
array__semidet_set(Array0, Index, Item, Array) :-
- array__in_bounds(Array0, Index),
- array__set(Array0, Index, Item, Array).
+ ( if array__in_bounds(Array0, Index) then
+ array__unsafe_set(Array0, Index, Item, Array)
+ else
+ fail
+ ).
array__semidet_slow_set(Array0, Index, Item, Array) :-
- array__in_bounds(Array0, Index),
- array__slow_set(Array0, Index, Item, Array).
+ ( if array__in_bounds(Array0, Index) then
+ array__slow_set(Array0, Index, Item, Array)
+ else
+ fail
+ ).
array__slow_set(Array0, Index, Item, Array) :-
array__copy(Array0, Array1),
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list