[m-rev.] for review: add io.write_array/[56] and array2d.is_empty/1

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Mar 18 12:38:19 AEDT 2016



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

The diff is otherwise fine.

Zoltan.


More information about the reviews mailing list