[m-rev.] for review: delete obsolete procedures from string module

Julien Fischer jfischer at opturion.com
Wed Apr 13 16:11:50 AEST 2022


For review by anyone.

Again, the review request is just in case anyone has objections to
any of these deletions.

---------------------------------

Delete obsolete procedures from string module.

library/string.m:
     Delete procedures that have been marked as obsolete since 2019.

NEWS:
     Announce the deletions.

tests/hard_coded/string_append_ooi.m:
tests/hard_coded/string_append_ooi_ilseq.m:
tests/hard_coded/string_presuffix.{m,exp}:
     Conform to the above changes.

Julien.

diff --git a/NEWS b/NEWS
index 70c8d33..b804b5b 100644
--- a/NEWS
+++ b/NEWS
@@ -239,6 +239,16 @@ As a result, the following predicates have been removed:
     - pred `permutation/4`
              (replacement: `random.shuffle_list/4` or `random.shuffle_list/5`)

+### Changes to the `string` module
+
+* The following obsolete procedures have been removed:
+
+   - pred `to_char_list(uo, in)`
+   - pred `to_rev_char_list(in, out)`
+   - pred `append(out, out, in)`
+   - pred `prefix(in, out)`
+   - pred `suffix(in out)`
+
  ### Changes to the `term_io` module

  * The following predicates have been removed:
diff --git a/library/string.m b/library/string.m
index 21b6c65..2ff63cc 100644
--- a/library/string.m
+++ b/library/string.m
@@ -121,65 +121,32 @@

      % Convert the string to a list of characters (code points).
      %
-    % In the forward mode:
      % If strings use UTF-8 encoding then each code unit in an ill-formed
      % sequence is replaced by U+FFFD REPLACEMENT CHARACTER in the list.
      % If strings use UTF-16 encoding then each unpaired surrogate code point
      % is returned as a separate code point in the list.
      %
-    % The reverse mode of the predicate throws an exception if the list
-    % contains a null character or code point that cannot be encoded in a
-    % string (namely, surrogate code points cannot be encoded in UTF-8
-    % strings).
-    %
-    % The reverse mode of to_char_list/2 is deprecated because the implied
-    % ability to round trip convert a string to a list then back to the same
-    % string does not hold in the presence of ill-formed code unit sequences.
-    %
-:- pragma obsolete_proc(to_char_list(uo, in), [from_char_list/2]).
  :- func to_char_list(string) = list(char).
-:- pred to_char_list(string, list(char)).
-:- mode to_char_list(in, out) is det.
-:- mode to_char_list(uo, in) is det.
+:- pred to_char_list(string::in, list(char)::out) is det.

      % Convert the string to a list of characters (code points) in reverse
      % order.
      %
-    % In the forward mode:
      % If strings use UTF-8 encoding then each code unit in an ill-formed
      % sequence is replaced by U+FFFD REPLACEMENT CHARACTER in the list.
      % If strings use UTF-16 encoding then each unpaired surrogate code point
      % is returned as a separate code point in the list.
      %
-    % The reverse mode of the predicate throws an exception if the list
-    % contains a null character or code point that cannot be encoded in a
-    % string (namely, surrogate code points cannot be encoded in UTF-8
-    % strings).
-    %
-    % The reverse mode of to_rev_char_list/2 is deprecated because the implied
-    % ability to round trip convert a string to a list then back to the same
-    % string does not hold in the presence of ill-formed code unit sequences.
-    %
-:- pragma obsolete_proc(to_rev_char_list(uo, in), [from_rev_char_list/2]).
  :- func to_rev_char_list(string) = list(char).
-:- pred to_rev_char_list(string, list(char)).
-:- mode to_rev_char_list(in, out) is det.
-:- mode to_rev_char_list(uo, in) is det.
+:- pred to_rev_char_list(string::in, list(char)::out) is det.

      % Convert a list of characters (code points) to a string.
      % Throws an exception if the list contains a null character or code point
      % that cannot be encoded in a string (namely, surrogate code points cannot
      % be encoded in UTF-8 strings).
      %
-    % The reverse mode of from_char_list/2 is deprecated because the implied
-    % ability to round trip convert a string to a list then back to the same
-    % string does not hold in the presence of ill-formed code unit sequences.
-    %
-:- pragma obsolete_proc(from_char_list(out, in), [to_char_list/2]).
  :- func from_char_list(list(char)::in) = (string::uo) is det.
-:- pred from_char_list(list(char), string).
-:- mode from_char_list(in, uo) is det.
-:- mode from_char_list(out, in) is det.
+:- pred from_char_list(list(char)::in, string::uo) is det.

      % As above, but fail instead of throwing an exception if the list contains
      % a null character or code point that cannot be encoded in a string.
@@ -713,17 +680,11 @@
      % ill-formed code unit sequence at the start of S2 to produce a valid
      % encoding of a code point in S3.
      %
-    % The append(out, out, in) mode is deprecated because it does not match
-    % the semantics of the forwards modes in the presence of ill-formed code
-    % unit sequences. Use nondet_append/3 instead.
-    %
-:- pragma obsolete_proc(append(out, out, in), [nondet_append/3]).
  :- pred append(string, string, string).
  :- mode append(in, in, in) is semidet.  % implied
  :- mode append(in, uo, in) is semidet.
  :- mode append(in, in, uo) is det.
  :- mode append(uo, in, in) is semidet.
-:- mode append(out, out, in) is multi.

      % nondet_append(S1, S2, S3):
      %
@@ -972,18 +933,14 @@
      % prefix(String, Prefix) is true iff Prefix is a prefix of String.
      % Same as append(Prefix, _, String).
      %
-:- pragma obsolete_proc(prefix(in, out)).
  :- pred prefix(string, string).
  :- mode prefix(in, in) is semidet.
-:- mode prefix(in, out) is multi.

      % suffix(String, Suffix) is true iff Suffix is a suffix of String.
      % Same as append(_, Suffix, String).
      %
-:- pragma obsolete_proc(suffix(in, out)).
  :- pred suffix(string, string).
  :- mode suffix(in, in) is semidet.
-:- mode suffix(in, out) is multi.

      % remove_prefix(Prefix, String, Suffix):
      %
@@ -1777,12 +1734,8 @@
  to_char_list(S) = Cs :-
      to_char_list(S, Cs).

-:- pragma promise_equivalent_clauses(pred(to_char_list/2)).
-
  to_char_list(Str::in, CharList::out) :-
      do_to_char_list(Str, CharList).
-to_char_list(Str::uo, CharList::in) :-
-    from_char_list(CharList, Str).

  :- pred do_to_char_list(string::in, list(char)::out) is det.

@@ -1805,12 +1758,8 @@ do_to_char_list_loop(Str, Index0, !CharList) :-
  to_rev_char_list(S) = Cs :-
      to_rev_char_list(S, Cs).

-:- pragma promise_equivalent_clauses(pred(to_rev_char_list/2)).
-
  to_rev_char_list(Str::in, CharList::out) :-
      do_to_rev_char_list(Str, CharList).
-to_rev_char_list(Str::uo, CharList::in) :-
-    from_rev_char_list(CharList, Str).

  :- pred do_to_rev_char_list(string::in, list(char)::out) is det.

@@ -1837,10 +1786,6 @@ do_to_rev_char_list_loop(Str, Index0, !RevCharList) :-
  from_char_list(Cs) = S :-
      from_char_list(Cs, S).

-:- pragma promise_equivalent_clauses(pred(from_char_list/2)).
-
-from_char_list(Chars::out, Str::in) :-
-    to_char_list(Str, Chars).
  from_char_list(Chars::in, Str::uo) :-
      ( if semidet_from_char_list(Chars, Str0) then
          Str = Str0
@@ -3637,8 +3582,6 @@ append(S1::in, S2::in, S3::uo) :-
      append_iio(S1, S2, S3).
  append(S1::uo, S2::in, S3::in) :-
      append_oii(S1, S2, S3).
-append(S1::out, S2::out, S3::in) :-
-    nondet_append(S1, S2, S3).

  :- pred append_iii(string::in, string::in, string::in) is semidet.

@@ -4438,43 +4381,14 @@ split_into_lines_loop(Str, CurPos, !RevLines) :-
  % Dealing with prefixes and suffixes.
  %

-:- pragma promise_equivalent_clauses(pred(prefix/2)).
-
  prefix(String::in, Prefix::in) :-
      compare_substrings((=), String, 0, Prefix, 0, length(Prefix)).
-prefix(String::in, Prefix::out) :-
-    prefix_2_ioi(String, Prefix, 0).
-
-:- pred prefix_2_ioi(string::in, string::out, int::in) is multi.
-
-prefix_2_ioi(String, Prefix, Cur) :-
-    (
-        Prefix = unsafe_between(String, 0, Cur)
-    ;
-        unsafe_index_next(String, Cur, Next, _),
-        prefix_2_ioi(String, Prefix, Next)
-    ).
-
-:- pragma promise_equivalent_clauses(pred(suffix/2)).

  suffix(String::in, Suffix::in) :-
      StringLength = length(String),
      SuffixLength = length(Suffix),
      StringStart = StringLength - SuffixLength,
      compare_substrings((=), String, StringStart, Suffix, 0, SuffixLength).
-suffix(String::in, Suffix::out) :-
-    Len = length(String),
-    suffix_2_ioii(String, Suffix, Len, Len).
-
-:- pred suffix_2_ioii(string::in, string::out, int::in, int::in) is multi.
-
-suffix_2_ioii(String, Suffix, Cur, Len) :-
-    (
-        unsafe_between(String, Cur, Len, Suffix)
-    ;
-        unsafe_prev_index(String, Cur, Prev, _),
-        suffix_2_ioii(String, Suffix, Prev, Len)
-    ).

  %---------------------%

diff --git a/tests/hard_coded/string_append_ooi.m b/tests/hard_coded/string_append_ooi.m
index 5bb87ab..3475bd5 100644
--- a/tests/hard_coded/string_append_ooi.m
+++ b/tests/hard_coded/string_append_ooi.m
@@ -24,8 +24,7 @@
  main(!IO) :-
      unsorted_solutions(
          ( pred(L - R::out) is multi :-
-            string.append(L, R, "cat")
+            string.nondet_append(L, R, "cat")
          ), UnsortedSolutions),
      list.sort(UnsortedSolutions, Solutions),
-    io.write(Solutions, !IO),
-    io.nl(!IO).
+    io.write_line(Solutions, !IO).
diff --git a/tests/hard_coded/string_append_ooi_ilseq.m b/tests/hard_coded/string_append_ooi_ilseq.m
index e4199df..4fa608b 100644
--- a/tests/hard_coded/string_append_ooi_ilseq.m
+++ b/tests/hard_coded/string_append_ooi_ilseq.m
@@ -38,7 +38,7 @@ main(!IO) :-
  :- pred test_append_ooi(string::in, pair(string, string)::out) is multi.

  test_append_ooi(S, L - R) :-
-    string.append(L, R, S).
+    string.nondet_append(L, R, S).

  :- pred write_result(pair(string, string)::in, io::di, io::uo) is det.

diff --git a/tests/hard_coded/string_presuffix.exp b/tests/hard_coded/string_presuffix.exp
index fc6f2c5..ff38bd0 100644
--- a/tests/hard_coded/string_presuffix.exp
+++ b/tests/hard_coded/string_presuffix.exp
@@ -1,15 +1,9 @@
  prefix(in, in):
  pass

-prefix(in, out):
-["", "a", "aß", "aßξ", "aßξ啕", "aßξ啕𐀀", "aßξ啕𐀀."]
-
  suffix(in, in):
  pass

-suffix(in, out):
-["", ".", "aßξ啕𐀀.", "ßξ啕𐀀.", "ξ啕𐀀.", "啕𐀀.", "𐀀."]
-
  remove_prefix:
  pass

diff --git a/tests/hard_coded/string_presuffix.m b/tests/hard_coded/string_presuffix.m
index c07e9cf..3413785 100644
--- a/tests/hard_coded/string_presuffix.m
+++ b/tests/hard_coded/string_presuffix.m
@@ -42,11 +42,6 @@ main(!IO) :-
          io.write_string("fail\n", !IO)
      ),

-    io.write_string("\nprefix(in, out):\n", !IO),
-    solutions(pred(Pre::out) is multi :- string.prefix(Str, Pre), Prefixes),
-    io.write(Prefixes, !IO),
-    io.nl(!IO),
-
      io.write_string("\nsuffix(in, in):\n", !IO),
      ( if
          not string.suffix(Str, "aßξ啕𐀀.z"),
@@ -63,11 +58,6 @@ main(!IO) :-
          io.write_string("fail\n", !IO)
      ),

-    io.write_string("\nsuffix(in, out):\n", !IO),
-    solutions(pred(Suf::out) is multi :- string.suffix(Str, Suf), Suffixes),
-    io.write(Suffixes, !IO),
-    io.nl(!IO),
-
      io.write_string("\nremove_prefix:\n", !IO),
      ( if
          string.remove_prefix(Str, Str, ""),


More information about the reviews mailing list