[m-rev.] for review: add io.write_array/ and array2d.is_empty/1
jfischer at opturion.com
Fri Mar 18 13:03:14 AEDT 2016
On Fri, 18 Mar 2016, Zoltan Somogyi wrote:
> On Fri, 18 Mar 2016 12:03:26 +1100 (AEDT), Julien Fischer <jfischer at opturion.com> wrote:
>> +do_write_array(Array, Separator, OutputPred, I, Hi, !IO) :-
>> + ( if I =< Hi then
>> + array.unsafe_lookup(Array, I, E),
>> + OutputPred(E, !IO),
>> + ( if I < Hi
>> + then io.write_string(Separator, !IO)
>> + else true
>> + ),
>> + do_write_array(Array, Separator, OutputPred, I + 1, Hi, !IO)
>> + else
>> + true
>> + ).
> We want to write N elements but only N-1 separators.
> It would be better to write the first element in write_array,
> and to always write a separator/element pair in do_write_array.
> This would allow us to do only one test in each loop
Done -- thanks for the review.
More information about the reviews