[m-rev.] for review: carve four modules out of term.m

Julien Fischer jfischer at opturion.com
Tue Aug 23 12:28:27 AEST 2022



On Tue, 23 Aug 2022, Zoltan Somogyi wrote:

> 2022-08-20 15:44 GMT+10:00 "Julien Fischer" <jfischer at opturion.com>:
>>> Opinions?
>>
>> As a starting point, I would move context to its own module, e.g.
>> term_context.
>
> The attached diff does this. It is mostly boring and not worth looking at,
> but I would like you all to look at the new term_context.m and see whether
> you agree with the updated names of some functions, and with the fact that
> the diff effectively deletes predicates that duplicate the functionality of
> functions. These are marked with ZZZs, so they can be added back in
> if people want them.

Removing the predicates marked with ZZZ is fine by me.

> Carve term_context.m out of term.m.
> 
> library/term.m:
> library/term_context.m:
>     As above.
>
>     Rename the term.context type as term_context.term_context, with
>     term.context now being defined as an equivalence type.
>
>     Replace the context_init function and predicate and the dummy_context_init
>     function with just one function: dummy_context. This name includes
>     the important part (the fact that it return a *dummy* context) and deletes
>     the nonimportant part (dummy contexts are just about never updated,
>     so the function does not really "initialize" them).
>
>     ZZZ Reduce function/predicate pairs that do the same thing to just a
>     function.
> 
> library/MODULES_DOC:
> library/library.m:
>     Add the new module to the list of standard library modules.
> 
> NEWS:
>     Mention the new module, and the obsoleting of the moved predicates
>     and functions in term.m.
> 
> compiler/*.m:
> library/*.m:
>     Conform to the changes above.

...

> +%---------------------------------------------------------------------------%
> +% vim: ts=4 sw=4 et ft=mercury
> +%---------------------------------------------------------------------------%
> +% Copyright (C) 1993-2000,2003-2009,2011-2012 The University of Melbourne.
> +% Copyright (C) 2014-2022 The Mercury team.
> +% This file is distributed under the terms specified in COPYING.LIB.
> +%---------------------------------------------------------------------------%
> +%
> +% File: term.m.
> +% Main author: fjh.
> +% Stability: medium.
> +%
> +% This file provides a type `term' used to represent Herbrand terms,
> +% and various predicates to manipulate terms and substitutions.

That description is a copy-and-paste error.

> +%---------------------------------------------------------------------------%
> +%---------------------------------------------------------------------------%
> +
> +:- module term_context.
> +:- interface.
> +
> +%---------------------------------------------------------------------------%
> +
> +:- type term_context
> +    --->    context(string, int).
> +            % file name, line number.

Is there any particular reason not to turn the above into field names?

> +    % Initialize the term context when reading in (or otherwise constructing)
> +    % a term.
> +    %
> +:- func context_init(string, int) = term_context.
> +% ZZZ :- pred context_init(string::in, int::in, term_context::out) is det.
> +
> +    % Return a dummy term context.
> +    %
> +:- func dummy_context = term_context.
> +
> +    % Is the given context a dummy context, as returned by dummy_context_init?
> +    %
> +:- pred is_dummy_context(term_context::in) is semidet.
> +
> +    % Given a term context, return the source file.
> +    %
> +:- func context_file(term_context) = string.
> +% ZZZ :- pred context_file(term_context::in, string::out) is det.
> +
> +    % Given a term context, return the source line number.
> +    %
> +:- func context_line(term_context) = int.
> +% ZZZ :- pred context_line(term_context::in, int::out) is det.

That's fine otherwise.

Julien.


More information about the reviews mailing list