[m-rev.] for post-commit review: gap_foldl, last_gap_foldl, and chunk_foldl[1-4]

Peter Wang novalazy at gmail.com
Wed Mar 16 13:30:30 AEDT 2022


On Tue, 15 Mar 2022 12:17:54 +1100 "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> Add gap_foldl, last_gap_foldl, chunk_foldl{,2,3,4}.
> 
> library/list.m:
>     Add the above predicates to the list module.
> 
> NEWS:
>     Announce the new predicates.
> 
> tests/hard_coded/fold_tests.{m,exp}:
>     Test case for the new functionality.
> 
> tests/hard_coded/Mmakefile:
>     Enable the new test case.

> diff --git a/NEWS b/NEWS
> index d93a15c39..4c2e0d01f 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -1366,6 +1365,105 @@
>      in, in, out, in, out, in, out, in, out, in, out,
>      in, out, in, out, in, out) is nondet.
>  
> +%---------------------%
> +
> +    % gap_foldl(ProcessPred, GapPred, List, !Acc):
> +    %
> +    % Invoke ProcessPred on every element of List,
> +    % and invoke GapPred on every gap *between* elements in List.
> +    % The intended use case is printing a list, using ProcessPred to print
> +    % each element, and using GapPred to print e.g. commas between
> +    % the elements.
> +    %
> +:- pred gap_foldl(pred(L, A, A), pred(A, A), list(L), A, A).
> +:- mode gap_foldl(pred(in, di, uo) is det, pred(di, uo) is det,
> +    in, di, uo) is det.
> +:- mode gap_foldl(pred(in, in, out) is det, pred(in, out) is det,
> +    in, in, out) is det.

"gap" is okay, but how about "sep"?

I've known the "insert separator between list elements" function as
"intersperse" (from the Haskell Prelude), so another suggestion could
be "intersperse_foldl".

That's fine, though.

Peter


More information about the reviews mailing list