[m-rev.] for review: anon_var_info
Julien Fischer
jfischer at opturion.com
Tue Jun 20 10:49:04 AEST 2023
On Mon, 19 Jun 2023, Zoltan Somogyi wrote:
> Support two ways to write unnamed vars.
>
> library/term_io.m:
> Replace the !N threaded through the code writing out terms, which was
> used only in commented-out code, with a value of a new type,
> anon_var_info, being threaded through. The two values of this type
> each choose one of two ways to write out unnamed variables.
> This capability is not yet exposed to users.
>
> diff --git a/library/term_io.m b/library/term_io.m
> index b5426035b..138482fa9 100644
> --- a/library/term_io.m
> +++ b/library/term_io.m
> @@ -46,13 +46,14 @@
> :- pred write_term_with_op_table(io.text_output_stream::in, OpTable::in,
> varset(T)::in, term(T)::in, io::di, io::uo) is det <= op_table(OpTable).
>
> - % As above, except it appends a period and new-line.
> + % As write_term, except it appends a period and a newline character.
I would delete character since on some systems a newline is multiple characters.
> %
> :- pred write_term_nl(varset(T)::in, term(T)::in, io::di, io::uo) is det.
> :- pred write_term_nl(io.text_output_stream::in, varset(T)::in, term(T)::in,
> io::di, io::uo) is det.
>
> - % As above, except it appends a period and new-line.
> + % As write_term_with_op_table above, except it appends a period
> + % and a newline character.
Ditto.
> %
> :- pred write_term_nl_with_op_table(OpTable::in,
> varset(T)::in, term(T)::in, io::di, io::uo) is det <= op_table(OpTable).
> @@ -276,7 +278,8 @@ write_term_with_op_table(OpTable, VarSet, Term, !IO) :-
> write_term_with_op_table(OutStream, OpTable, VarSet, Term, !IO).
>
> write_term_with_op_table(OutStream, OpTable, VarSet, Term, !IO) :-
> - write_term_anon_vars(OutStream, OpTable, Term, VarSet, _, 0, _, !IO).
> + write_term_anon_vars(OutStream, OpTable, Term, VarSet, _,
> + anon_var_to_int, _, !IO).
>
> %---------------------%
>
...
> @@ -701,7 +711,20 @@ write_variable_with_op_table(OpTable, Var, VarSet, !IO) :-
> write_variable_with_op_table(OutStream, OpTable, Var, VarSet, !IO).
>
> write_variable_with_op_table(OutStream, OpTable, Var, VarSet, !IO) :-
> - write_variable_anon_vars(OutStream, OpTable, Var, VarSet, _, 0, _, !IO).
> + write_variable_anon_vars(OutStream, OpTable, Var, VarSet, _,
> + anon_var_to_int, _, !IO).
> +
> +:- type anon_var_info
> + ---> anon_var_to_int
> + % The string we use to write out an anonymous variable
> + % should be derived from its variable number, obtained
> + % by calling var_to_int on it.
> + ; anon_occur_order(counter).
> + % The string we use to write out an anonymous variable
> + % should be based on whether it is the first, second, third etc
> + % anonymous variable that our traversal of the whole term
> + % has encountered. The counter tells us the number we should give
> + % to the *next* one we encounter.
>
> % Write a variable.
> %
> @@ -709,49 +732,58 @@ write_variable_with_op_table(OutStream, OpTable, Var, VarSet, !IO) :-
> %
> % 1 Convert the variable to the integer that represents it and write
> % `_N' where N is that integer. This has the advantage that
> - % such variables get printed in a canonical way, so rearranging terms
> - % containing such variables will not effect the way they are numbered
> - % (this includes breaking up a term and printing the pieces separately).
> + % such variables get printed in a canonical way, so rearranging terms
> + % containing such variables will not effect the way they are numbered
s/effect/affect/
The diff looks fine otherwise.
Julien.
More information about the reviews
mailing list