[m-rev.] for review: implement --warn-suspicious-recursion

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed May 1 21:05:27 AEST 2019



On Wed, 1 May 2019 15:22:58 +1000, Peter Wang <novalazy at gmail.com> wrote:
> On Wed, 01 May 2019 12:13:49 +1000 (AEST), "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> > +:- pred delete_any_numeric_suffix(string::in, string::out) is det.
> > +
> > +delete_any_numeric_suffix(Str, StrNoSuffix) :-
> > +    ( if has_numeric_suffix(Str, StrNoSuffixPrime) then
> > +        StrNoSuffix = StrNoSuffixPrime
> > +    else
> > +        StrNoSuffix = Str
> > +    ).
> 
> It would be straightforward to avoid converting the string to a list and
> back. I can do that later if you wish.

Yes, thank you, I would like that.

> > diff --git a/library/string.m b/library/string.m
> > index 251dfed..ad6bbf7 100644
> > --- a/library/string.m
> > +++ b/library/string.m
> > @@ -115,6 +115,7 @@
> >  
> >      % Convert the string to a list of characters (code points).
> >      % Throws an exception if the list of characters contains a null character.
> > +    % XXX I (zs) see no code that would throw this exception.
> >      %
> >      % NOTE: In the future we may also throw an exception if the list contains
> >      % a surrogate code point.
> 
> That happens in the reverse mode of to_char_list, i.e. from_char_list.

OK. I have replaced both the XXX line and the line before it (in both places)
with this:

% The reverse mode of the predicate throws an exception if
% the list of characters contains a null character.


> > +do_to_rev_char_list(Str, RevCharList) :-
> > +    do_to_char_list(Str, CharList),
> > +    list.reverse(CharList, RevCharList).
> 
> do_to_char_list can be written efficiently in Mercury using unsafe_index_next.
> I can do that later if you wish.

Again, yes, thank you.

I followed all your other suggestions.

Zoltan.


More information about the reviews mailing list