[m-rev.] for review: add array.fill/3, array.fill_range/5 and array2d.fill/3

Peter Wang novalazy at gmail.com
Thu Nov 8 17:54:16 AEDT 2018


On Tue, 6 Nov 2018 04:41:30 +0000 (UTC), Julien Fischer <jfischer at opturion.com> wrote:
> 
> For review by anyone.
> 
> -----------------------
> 
> Add array.fill/3, array.fill_range/5 and array2d.fill/3.
> 
> library/array.m:
> library/array2d.m:
>      Add the new predicates.
> 
>      Add a note a likely problem with another predicate.
> 
> NEWS:
>      Announce them.
> 
> tests/hard_coded/Mmakfile:
> tests/hard_coded/array_fill.{m,exp}:
>      Add a test case.
> 
> Julien.

> diff --git a/library/array.m b/library/array.m
> index 9118bd4..a4dea56 100644
> --- a/library/array.m
> +++ b/library/array.m
> @@ -377,6 +377,19 @@
>   :- func shrink(array(T), int) = array(T).
>   :- mode shrink(array_di, in) = array_uo is det.
> 
> +    % fill(Item, Array0, Array):
> +    % Sets every element of the array to `Elem'.
> +    %
> +:- pred fill(T::in, array(T)::array_di, array(T)::array_uo) is det.
> +
> +    % fill_range(Item, Lo, Hi, !Array):
> +    % Sets every element of the array with index in the range Lo..Hi
> +    % (inclusive) to Item. Throws a software_error1/ exception if Lo > Hi.
> +    % Throws an index_out_of_bound/0 exception if Lo or Hi is out of bounds.
> +    %
> +:- pred fill_range(T::in, int::in, int::in,
> +     array(T)::array_di, array(T)::array_uo) is det.

Seems alright to me. (I would prefer half-open ranges but it seems the
standard library generally has inclusive Hi arguments.)

> diff --git a/library/array2d.m b/library/array2d.m
> index 118fbe6..74ac1a9 100644
> --- a/library/array2d.m
> +++ b/library/array2d.m
> @@ -128,6 +128,11 @@
>   %:- mode lists(array2d_ui) = out is det.
>   :- mode lists(in        ) = out is det.
> 
> +    % fill(Item, !Array2d:)

Typo.

Peter


More information about the reviews mailing list