[m-rev.] for review: move char_to_doc to pretty_printer.m

Julien Fischer jfischer at opturion.com
Wed Dec 21 12:57:19 AEDT 2022


On Tue, 20 Dec 2022, Zoltan Somogyi wrote:

> Move X_to_doc functions to pretty_printer.m.

...

> diff --git a/library/pretty_printer.m b/library/pretty_printer.m
> index 4d47976ac..2a97bd66f 100644
> --- a/library/pretty_printer.m
> +++ b/library/pretty_printer.m
> +array_to_doc(A) =
> +    docs([str("array(["), array_to_doc_loop(A, 0), str("])")]).
> +
> +:- func array_to_doc_loop(array(T), int) = doc.
> +
> +array_to_doc_loop(A, I) = Doc :-
> +    ( if I > array.max(A) then
> +        Doc = str("")
> +    else
> +        array.lookup(A, I, Elem),

It should be safe to call unsafe_lookup/3 there.

> +        Doc = docs([
> +            format_arg(format(Elem)),
> +            ( if I = array.max(A) then
> +                str("")
> +            else
> +                group([str(", "), nl])
> +            ),
> +            format_susp((func) = array_to_doc_loop(A, I + 1))
> +        ])
> +    ).

Ditto for the version_array version.

Julien.


More information about the reviews mailing list