[m-rev.] for review: string__substring in Mercury
Ralph Becket
rbeck at microsoft.com
Fri Sep 7 23:54:55 AEST 2001
> From: Ralph Becket [mailto:rbeck at microsoft.com]
> Sent: 07 September 2001 14:49
>
> A slightly more efficient way of doing this is
>
> string__substring(Str::in, Start::in, Count::in, SubStr::out) :-
> End = min(Start + Count, string__length(Str)),
> SubStr = string__from_char_list(strchars(Start, End, Str)).
>
> :- func strchars(int, int, string) = list(char).
>
> strchars(I, End, Str) =
> ( if I >= End
> then []
> else [string__index_det(Str, I) | strchars(I + 1, End, Str)]
> ).
>
> This way we avoid creating any more cons cells than strictly
> necessary.
Sorry, this isn't quite correct: strchars should be
strchars(I, End, Str) =
( if ( I < 0 ; End =< I )
then []
else [string__index_det(Str, I) | strchars(I + 1, End, Str)]
).
since string__substring/3 is defined when Start is out of range.
- Ralph
--------------------------------------------------------------------------
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