[m-rev.] for review: Deprecate modes of string predicates that imply round-trippability.
Peter Wang
novalazy at gmail.com
Wed Oct 23 16:13:40 AEDT 2019
On Wed, 23 Oct 2019 15:45:58 +1100, Mark Brown <mark at mercurylang.org> wrote:
> Hi Peter,
>
> On Wed, Oct 23, 2019 at 12:54 PM Peter Wang <novalazy at gmail.com> wrote:
> >
> > Mark pointed out that to_char_list/2 having multiple modes implies the
> > ability to round trip convert between a string and list of chars,
> > which is not true if to_char_list replaces code units in ill-formed
> > sequences with U+FFFD; converting the list of chars back to a string
> > may produce a different string from the original input.
> >
> > library/string.m:
> > Deprecate reverse modes of to_char_list/2, to_rev_char_list/2,
> > from_char_list/2 and char_to_string/2.
>
> Not the last one, but I see you already noticed that.
I don't understand what you mean by this.
Oh, the reverse mode of char_to_string is semidet, unlike the others.
I can back out the changes to char_to_string and leave it for another
change.
> > @@ -5726,8 +5726,13 @@ det_to_float(FloatString) = Float :-
> > char_to_string(C) = S1 :-
> > char_to_string(C, S1).
> >
> > -char_to_string(Char, String) :-
> > - to_char_list(String, [Char]).
> > +:- pragma promise_equivalent_clauses(char_to_string/2).
> > +
> > +char_to_string(Char::in, String::uo) :-
> > + from_char_list([Char], String).
> > +char_to_string(Char::out, String::in) :-
> > + string.index_next(String, 0, NextIndex, Char),
> > + string.length(String, NextIndex).
> >
>
> Does this work as intended? If the string contains an ill-formed
> sequence of one code unit, won't we get NextIndex = 1 and Char =
> U+FFFD?
Yes, but the intention was wrong ;)
Peter
More information about the reviews
mailing list