[mercury-users] Array bounds
Ralph Becket
rbeck at microsoft.com
Thu Mar 16 23:55:46 AEDT 2000
>From the interface, it looks like array.m may eventually handle arrays
that aren't indexed from 0. This would be no bad thing, but because
arrays currently are indexed from 0 I suspect that assumption has been
hard coded into most of the code around that manipulates arrays (if
only because it's less verbose...)
That is, I suspect common practice is to write
..., foo(A, 0, X), ...
:- func foo(array(T1), int, T2) = T2.
:- mode foo(array_ui, in, in) = out is det.
foo(A, I, X) =
( if I < array__size(A) then
foo(A, I + 1, bar(X, array__lookup(A, I)))
else
X
).
rather than
..., foo(A, array__min(A), X), ...
:- func foo(array(T1), int, T2) = T2.
:- mode foo(array_ui, in, in) = out is det.
foo(A, I, X) =
( if I =< array__max(A) then
foo(A, I + 1, bar(X, array__lookup(A, I)))
else
X
).
If the array type interface is changed to allow non-0 based arrays
then code of the first type is going to break. So what's the plan?
Ralph
--
Ralph Becket | MSR Cambridge | rbeck at microsoft.com
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list