[m-rev.] for review: atoms in the debugger

Ralph Becket rafe at cs.mu.OZ.AU
Wed Jan 2 11:34:09 AEDT 2002


Zoltan Somogyi, Monday, 31 December 2001:
> Index: library/pprint.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/pprint.m,v
> retrieving revision 1.6
> diff -u -b -r1.6 pprint.m
> --- library/pprint.m	2001/11/02 00:49:21	1.6
> +++ library/pprint.m	2001/12/29 00:41:38
> @@ -150,7 +150,7 @@
>  
>  :- interface.
>  
> -:- import_module int, string, list, io.
> +:- import_module std_util, bool, int, string, list, io.
>  
>      % Clients must translate data structures into docs for
>      % the pretty printer to display.
> @@ -293,6 +293,14 @@
>  :- func to_doc(T)           = doc.
>  :- func to_doc(int, T)      = doc.
>  
> +    % These two functions are just like like to_doc, except their input is not
> +    % a natural term, but a synthetic term defined by a functor, a list of
> +    % arguments, and a boolean that is true iff the synthetic term is a
> +    % function application, and thus should be printed not as f(a1, ... an)
> +    % but as f(a1, ... an-1) = an.
> +:- func synthetic_term_to_doc(string, list(univ), bool)           = doc.
> +:- func synthetic_term_to_doc(int, string, list(univ), bool)      = doc.
> +

Is this function of sufficiently general utility to make it part of the
interface to pprint?  Maybe it would be better off in a util module
specific to the term browser?

>      % Convert docs to pretty printed strings.  The int
>      % argument specifies a line width in characters.
>      %
> @@ -312,7 +320,7 @@
>  
>  :- implementation.
>  
> -:- import_module std_util, char, array, map.
> +:- import_module char, array, map, require.
>  
>  :- type doc
>      --->    'NIL'
> @@ -568,6 +576,8 @@
>  %------------------------------------------------------------------------------%
>  
>  to_doc(X) = to_doc(int__max_int, X).
> +synthetic_term_to_doc(Functor, Args, IsFunc) =
> +    synthetic_term_to_doc(int__max_int, Functor, Args, IsFunc).

The convention in pprint is to have a couple of blank lines around a
%----% separator comment between those two definitions.

>  
>  %------------------------------------------------------------------------------%
>  
> @@ -597,6 +607,53 @@
>        else    generic_term_to_doc(Depth, X)
>      ).
>  
> +synthetic_term_to_doc(Depth, Functor, Args, IsFunc) = Doc :-
> +    list__length(Args, Arity),

s/list__length(Args, Arity)/Arity = list__length(Args)/

> +    ( Depth =< 0 ->
> +        ( Arity = 0 ->
> +            Doc = text(Functor)
> +        ;
> +            IsFunc = yes,
> +            Doc = text(Functor) `<>` text("/") `<>` poly(i(Arity - 1))
> +                `<>` text("+1") 
> +        ;
> +            IsFunc = no,
> +            Doc = text(Functor) `<>` text("/") `<>` poly(i(Arity))
> +        )

Minor point: the rest of pprint uses if-then-else rather than (_ -> _ ; _).

I'm also slightly uncomfortable about combining a switch with the else
clause - it might be clearer to put the switch in parentheses.

> +    ;
> +        ( Arity = 0 ->
> +            Doc = text(Functor)
> +        ;
> +            (
> +                IsFunc = yes,
> +                list__length(Args, NumArgs),
Ditto.

> +                (
> +                    list__split_list(NumArgs - 1, Args, PredArgsPrime,
> +                        FuncArgs),
> +                    FuncArgs = [FuncArgPrime]
> +                ->
> +                    PredArgs = PredArgsPrime,
> +                    FuncArg = FuncArgPrime
> +                ;
> +                    error("synthetic_term_to_doc: length mismatch")
> +                ),
> +                Doc = group(
> +                        text(Functor) `<>` parentheses(
> +                            nest(2, packed_cs_univ_args(Depth - 1, PredArgs))
> +                        ) `<>`
> +                        nest(2, text(" = ") `<>` to_doc(Depth - 1, FuncArg))
> +                    )
> +            ;
> +                IsFunc = no,
> +                Doc = group(
> +                        text(Functor) `<>` parentheses(
> +                            nest(2, packed_cs_univ_args(Depth - 1, Args))
> +                        )
> +                    )
> +            )
> +        )
> +    ).
> +
>  %------------------------------------------------------------------------------%
>  
>  :- some [T2] pred dynamic_cast_to_array(T1, array(T2)).
> @@ -696,7 +753,7 @@
>  
>  out_of_depth_term_to_doc(X) = Doc :-
>  
> -    deconstruct(X, Name, Arity, _UnivArgs),
> +    functor(X, Name, Arity),
>  
>      Doc = ( if Arity = 0 then text(Name)
>                           else text(Name) `<>` text("/") `<>` poly(i(Arity))

Otherwise that looks fine.

- Ralph
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list