[m-rev.] for review: add array.all_{true,false}.2

Julien Fischer jfischer at opturion.com
Mon Jul 22 12:04:59 AEST 2013


Hi Paul,

On Mon, 22 Jul 2013, Paul Bone wrote:

>> @@ -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?

Better in what way?  (It is certainly more expensive which is probably
why we *don't* do that for list.all_false/2.)

> 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?

The latter.

>> 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.

Ok, I'll fix that up.

Cheers,
Julien.



More information about the reviews mailing list