[m-rev.] For review: updates to string.m

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Oct 14 23:04:31 AEST 2002


On 28-Jun-2002, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Some updates and additions to string.m.
...
> Index: string.m
> +:- func string__foldr_substring(func(char, T) = T, string, int, int, T) = T.
> +:- pred string__foldr_substring(pred(char, T, T), string, int, int, T, T).
> +:- mode string__foldr_substring(pred(in, in, out) is det, in, in, in,
> +		in, out) is det.
> +:- mode string__foldr_substring(pred(in, di, uo) is det, in, in, in,
> +		di, uo) is det.
> +:- mode string__foldr_substring(pred(in, in, out) is semidet, in, in, in,
> +		in, out) is semidet.
> +:- mode string__foldr_substring(pred(in, in, out) is nondet, in, in, in,
> +		in, out) is nondet.
> +:- mode string__foldr_substring(pred(in, in, out) is multi, in, in, in,
> +		in, out) is multi.
> +%	string__foldr_substring(Closure, String, Start, Count, Acc0, Acc)
> +%	is equivalent to string__foldr(Closure, SubString, Acc0, Acc)
> +%	where SubString = string__unsafe_substring(String, Start, Count).

If this is equivalent to something that calls unsafe_substring,
does that mean that this too is unsafe?

If so -- which I think is the case -- then it should have unsafe in the name,
and should be documented accordingly.

If not, then the comment should refer to string__substring
rather than string__unsafe_substring.

How expensive would it be to check the values of start and count here?
I don't think two tests are likely to be costly in comparison to
the cost of traversing the string (not to mention the higher-order
call, if it doesn't get specialized away).
So I don't think it is worth exporting the unsafe version of
this predicate, though it would be fine to use it from within string.m.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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