[m-rev.] Improved array error messages

Peter Ross peter.ross at miscrit.be
Wed Jan 16 12:05:52 AEDT 2002


On Wed, Jan 16, 2002 at 11:56:32AM +1100, Ralph Becket wrote:
> Peter Ross, Wednesday, 16 January 2002:
> > Ralph wrote:
> > > +
> > > +    % out_of_bounds_error(OpName, Array, Index) = IndexOutOfBounds.
> > > +    %
> > > +:- func out_of_bounds_error(string, array(T), int) = index_out_of_bounds.
> > > +
> > > +out_of_bounds_error(Op, A, I) =
> > > +    index_out_of_bounds(
> > > +        string__format("%s: array bounds [%d, %d], index %d",
> > > +        [s(Op), i(array__min(A)), i(array__max(A)), i(I)])
> > >      ).
> > >
> > I suggest printing out the type of the array which is similar to what is
> > done for map lookup failures.
> 
> Here's the relative diff:
> 
> --- array.m     16 Jan 2002 00:11:07 -0000
> +++ array.m     16 Jan 2002 00:54:17 -0000
> @@ -1616,8 +1616,11 @@
>  
>  out_of_bounds_error(Op, A, I) =
>      index_out_of_bounds(
> -        string__format("%s: array bounds [%d, %d], index %d",
> -           [s(Op), i(array__min(A)), i(array__max(A)), i(I)])
> +        string__format(
> +            "%s: array type %s, bounds [%d, %d], index %d",
> +            [s(Op), s(type_name(type_of(A))),
> +             i(array__min(A)), i(array__max(A)), i(I)]
> +       )
>      ).
>  
That looks fine.
--------------------------------------------------------------------------
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