[m-dev.] for review: destructive changes to string.m
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Nov 10 23:47:52 AEDT 2000
On 10-Nov-2000, Michael Day <mikeday at corplink.com.au> wrote:
>
> Allows checking string length without losing uniqueness and adds
> predicates to allow changing arbitrary characters in a string, handy for
> implementation of string streams.
>
> library/string.m:
> Added a new mode definition to string__length using unique input
> so as not to destroy uniqueness when checking string length.
>
> Added three new predicates, string__set, set_det and unsafe_set
> that allow changing arbitrary characters in a string. These function
> similarly to the corresponding index, index_det and unsafe_index
> predicates. (Is set an appropriate name? Overloading index/3 with
> index/4 is presumably a bad idea).
I suggest using `set_char' (and `set_char_det', `unsafe_set_char').
It might be better to make those functions rather than predicates.
> /*
> +:- pred string__set(char, int, string, string).
> +:- mode string__set(in, in, in, out) is semidet.
> +*/
> +:- pragma c_code(string__set(Ch::in, Index::in, Str0::in, Str::out),
> + [will_not_call_mercury, thread_safe], "
> + size_t len = strlen(Str0);
> + if ((MR_Word) Index >= len) {
s/MR_Word/MR_Unsigned/
(MR_Word should be treated as an opaque type,
if you want an unsigned type use MR_Unsigned.)
> +:- pragma c_code(string__set(Ch::in, Index::in, Str0::di, Str::uo),
> + [will_not_call_mercury, thread_safe], "
> + if ((MR_Word) Index >= strlen(Str0)) {
Likewise.
> :- func string__length(string) = int.
> +:- mode string__length(in) = uo is det.
You should add the `(ui) = uo' mode too.
Apart from that, this change looks fine.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list