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

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Apr 13 16:30:54 AEST 2022


2022-04-13 16:11 GMT+10:00 "Julien Fischer" <jfischer at opturion.com>:
> +### Changes to the `string` module
> +
> +* The following obsolete procedures have been removed:

Have we phrased it like this before? If not, I would instead suggest
"The following obsolete modes have been removed from the following predicates".
Reduces the risk of readers confusing "procedure" for "predicate".

> +   - 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)`

Missing comma on last line.

> -:- 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.

Same here.

> @@ -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).
> 

I would delete the modes on the args, since they are not needed anymore.
I would also inline the only call to do_to_char_list, since it is now indistinguishable
from to_char_list itself.

> @@ -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).
> 

The same two changes here.

> @@ -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

Again, no need for mode-specific clauses anymore.

> @@ -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).

And again.

> -:- 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).

And again.

The rest is fine.

Zoltan.


More information about the reviews mailing list