[m-rev.] for review: add array.all_{true,false}.2
Paul Bone
paul at bone.id.au
Mon Jul 22 11:11:42 AEST 2013
On Sun, Jul 21, 2013 at 01:27:00AM +1000, Julien Fischer wrote:
>
> For review by anyone.
>
> Add all_{true,false}/2 and is_empty/1 to array and version_array.
>
> library/array.m:
> library/version_array.m:
> Add the above predicates.
>
> NEWS:
> Announce the new predicates.
>
> tests/hard_coded/Mmakefile:
> tests/hard_coded/array_all_tf.{m,exp}:
> Test the new predicates.
>
> tests/hard_coded/version_array_test.{m,exp}:
> Extend this test case to cover the new predicates.
>
> Julien.
>
> @@ -2612,6 +2636,40 @@ array.map_corresponding_foldl_2(P, I, N, A, B, !C, !D) :-
> ).
>
> +
> +array.all_false(Pred, Array) :-
> + do_all_false(Pred, array.min(Array), array.max(Array), Array).
> +
> +:- pred do_all_false(pred(T), int, int, array(T)).
> +%:- mode do_all_false(in(pred(in) is semidet), in, in, array_ui) is semidet.
> +:- mode do_all_false(in(pred(in) is semidet), in, in, in) is semidet.
> +
> +do_all_false(Pred, I, UB, Array) :-
> + ( if I =< UB then
> + Elem = Array ^ unsafe_elem(I),
> + not Pred(Elem),
> + do_all_false(Pred, I + 1, UB, Array)
> + else
> + true
> + ).
> +
maybe I'm bikeshedding here. But would it not be better to implement
all_false in terms of all true by adding a closure?
Same for version_array.
> diff --git a/tests/hard_coded/Mmakefile b/tests/hard_coded/Mmakefile
> index acecc02..240d173 100644
> --- a/tests/hard_coded/Mmakefile
> +++ b/tests/hard_coded/Mmakefile
> @@ -11,6 +11,7 @@ ORDINARY_PROGS= \
> array_gen \
> array_test \
> array_test2 \
> + array_all_tf \
> backquoted_qualified_ops \
> bag_various \
> bidirectional \
Is this an indentation problem or is it your mail client?
> diff --git a/tests/hard_coded/array_all_tf.exp b/tests/hard_coded/array_all_tf.exp
> new file mode 100644
> index 0000000..65cf96c
> --- /dev/null
> +++ b/tests/hard_coded/array_all_tf.exp
> @@ -0,0 +1,4 @@
> +TEST: all_true(even, array([2, 4, 6, 8, 10]): PASSED
> +TEST: all_false(odd, array([2, 4, 6, 8, 10]): PASSED
> +TEST: all_true(even, array([]): PASSED
> +TEST: all_false(even, array([]): PASSED
A code path is not tested here. None of these predicates are tested to see
if they fail when they should.
The rest is fine.
Thanks.
--
Paul Bone
http://www.bone.id.au
More information about the reviews
mailing list