[m-rev.] for review: move same_type and find_functor to interface

Julien Fischer juliensf at csse.unimelb.edu.au
Tue Sep 25 11:27:55 AEST 2007


On Mon, 24 Sep 2007, Ondrej Bojar wrote:

> Incorporated Julien's suggestions:

Here are some more for you then :-)

> Estimated hours taken: 0
> Branch: main
>
> library/term.m:
> library/type_desc.m:
> library/construct.m:
>    Move same_type/2 and find_functor/5 from module term to interface of

s/to interface/into the interfaces of/

>    type_desc and construct, respectively. Both are useful in custom pickling
>    and unpickling predicates.
>
> NEWS:
>    Announce the change.
>
> Index: NEWS
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
> retrieving revision 1.478
> diff -u -r1.478 NEWS
> --- NEWS	21 Sep 2007 03:21:34 -0000	1.478
> +++ NEWS	24 Sep 2007 11:09:53 -0000
> @@ -197,6 +197,9 @@
>
> * We have added the predicate `dir.current_directory'.
>
> +* We have added public interface to two predicates useful for custom term
> +  construction: `construct.find_functor/5' and `type_desc.same_type/2'.

 	We have added two predicates that are useful for custom term
 	construction:
 		construct.find_functor/5
 		type_desc.same_type/2

So far as users are concerned they are new functionality.

...

> Index: library/construct.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/library/construct.m,v
> retrieving revision 1.40
> diff -u -r1.40 construct.m
> --- library/construct.m	18 Sep 2007 07:56:35 -0000	1.40
> +++ library/construct.m	24 Sep 2007 11:09:53 -0000
> @@ -92,6 +92,15 @@
> :- func get_functor_lex(type_desc, functor_number_ordinal) =
>     functor_number_lex is semidet.
>
> +    % find_functor(Type, FunctorName, Arity, FunctorNumber, ArgTypes).
> +    %
> +    % Given a type descriptor, a functor name and arity, finds the functor
> +    % number and the types of its arguments. It thus serves as the converse
> +    % to get_functor/5.
> +    %
> +:- pred find_functor(type_desc::in, string::in, int::in,
> +    functor_number_lex::out, list(type_desc)::out) is semidet.
> +
>     % construct(Type, I, Args) = Term.
>     %
>     % Returns a term of the type specified by Type whose functor
> @@ -116,6 +125,7 @@
> :- implementation.
>
> :- import_module require.
> +:- import_module int.

Please keep module imports in alphabetical order (as per the coding
standard).

> @@ -514,6 +524,28 @@
>     }
> }").
>
> +
> +
> +find_functor(Type, Functor, Arity, FunctorNumber, ArgTypes) :-
> +    N = construct.num_functors(Type),
> +    find_functor_2(Type, Functor, Arity, N, FunctorNumber, ArgTypes).
> +
> +:- pred find_functor_2(type_desc::in, string::in, int::in,
> +    int::in, int::out, list(type_desc)::out) is semidet.
> +
> +find_functor_2(TypeInfo, Functor, Arity, Num, FunctorNumber, ArgTypes) :-
> +    Num >= 0,
> +    Num1 = Num - 1,

I suggest s/Num/Num0/ and s/Num1/Num/ since that is way in which
sequences of variables are numbered throughout most of the rest
of the system.

> +    ( get_functor(TypeInfo, Num1, Functor, Arity, ArgPseudoTypes) ->
> +        ArgTypes = list.map(ground_pseudo_type_desc_to_type_desc_det,
> +            ArgPseudoTypes),
> +        FunctorNumber = Num1
> +    ;
> +        find_functor_2(TypeInfo, Functor, Arity, Num1, FunctorNumber, 
> ArgTypes)
> +    ).

...

> Index: library/type_desc.m
> ===================================================================
> RCS file: /home/mercury/mercury1/repository/mercury/library/type_desc.m,v
> retrieving revision 1.54
> diff -u -r1.54 type_desc.m
> --- library/type_desc.m	7 Sep 2007 05:08:17 -0000	1.54
> +++ library/type_desc.m	24 Sep 2007 11:09:53 -0000
> @@ -89,6 +89,12 @@
>     %
> :- some [T] pred has_type(T::unused, type_desc::in) is det.
>
> +
> +    % The predicate same_type/2 ensures type identity of the two arguments.
> +    %
> +:- pred same_type(T::unused, T::unused) is det.
> +

There seem to be a few too many blank lines around there.  Try to
keep the spacing (particularly in the module interface) consistent
with the existing code.

That looks okay otherwise.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list