[m-dev.] For review: added string__words/2

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Apr 14 04:45:43 AEST 2000


On 13-Apr-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> Question: I did `cvs diff -u string.m' to get the diff below and clearly
> my previous commit for string__length/1 didn't go through.  The command
> I used was
> $ cvs commit -F RALPHS_CHANGES_20000406 {array,std_util,string}.m
> Did I do something wrong?

Well, your commit certainly didn't get through.
I'm not sure why not.

> +++ string.m    2000/04/13 14:59:11
> @@ -214,6 +214,15 @@
>  %              list__foldl(Closure, Chars, Acc0, Acc)
>  %      but is implemented more efficiently.)
> 
> +:- func words(pred(char), string) = list(string).
> +:- mode words(pred(in) is semidet, in) = out is det.
> +%       words(SepP, String) returns the list of non-empty substrings of
> String
> +%       (in first to last order) that are delimited by non-empty sequences
> of
> +%       chars matched by SepP.  For example,
> +%
> +%       words(char__is_whitespace, " the cat  sat on the  mat") =
> +%               ["the", "cat", "sat", "on", "the", "mat"]

To avoid line wrapping in the printed manual,
please keep the comments in the interface to
less than about 60 characters in width.

For consistency with the other procedures in this
module, I suggest s/words/string__words/g here.

> +words(SepP, String) = words_0(SepP, String, I, [])
> +:-
> +    I = preceding_boundary(isnt(SepP), String, string__length(String) - 1).

To conform with the Mercury coding guidelines, s/_0/_2/g.
Also the `:-' should not be on a new line.

> +:- func words_0(pred(char), string, int, list(string)) = list(string).
> +:- mode words_0(pred(in) is semidet, in, in, in) = out is det.
> +
> +words_0(SepP, String, WordEnd, Words0) = Words
> +:-
> +    ( if WordEnd < 0 then
> +        Words = Words0
> +      else

Normally we indent the `;' for an if-then-else at the same level as the
`('.  The Mercury coding guidelines don't explicitly discuss layout
for the `(if ... then ... else ...)' form, but IMHO it should match the
layout for the `(... -> ... ; ...)' form.  (Any other opinions on this?)

Also please use 8-character indentation, to match that in the rest of
this module.  I'm happy for new modules to use 4-character indentation,
but it gets difficult if a single module contains a mix of 4- and
8-character indentation.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- 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