[m-dev.] for review: Added a new format "newpretty" to the browser.

Mark Anthony BROWN dougl at cs.mu.OZ.AU
Wed Jan 31 02:20:26 AEDT 2001


Hi,

I have just a few more review comments.  After you have addressed these,
and also Tyson's comment, please post a relative diff between the newest
version of the code and the previous version you posted.  If no further
issues arise, then I'll leave it to Fergus to make any other review
comments.

Cheers,
Mark.

Sarvamanan THURAIRATNAM writes:
> Estimated hours taken : 180
> 
> For Mark Brown to Review.
> 
> Added a new pretty printing format to the term browser. This new format helps
> put a limit on the size of the term printed during debugging. This limit is 
> specified by setting the number of lines you want the term to be printed on 
> and the width of these lines. Refer to sized_pretty.m for Examples.
> 
> browser/sized_pretty.m:
>         New file that does what's described above.
> browser/browse.m:
>         Modified to accommodate the new format.
> browser/browser_info.m:
>         Modified to accommodate the new format.
> browser/parse.m:
>         Modified to accommodate the new format.
> trace/mercury_trace_browse.c:
>         Modified to accommodate the new format.
> trace/mercury_trace_browse.h:
>         Modified to accommodate the new format.
> trace/mercury_trace_internal.c:
>         Modified to accommodate the new format.
> 
> I have fixed all of what was said in the review except these:
> 
> %------------------------------------------------------------------------------%
> 
> > +:- pred functor_count_split(univ::in, measure_params::in, functor_count::in, 
> > + int::in, bool::in, functor_count::out, maybe(functor_count)::out, 
> > + functor_count::out, measure_params::out) is det. 
> > + 
> > +functor_count_split(_, X, functor_count(Limit), Arity, _, functor_count(1), 
> > + Flag, functor_count(Limit), X) :- 
> 
> `Flag' is not a good variable name for something that is not a boolean flag. 
> We generally use the form `MaybeSomething' for variables with type maybe(...). 
> The same goes for the other instances.
> 
> The reason this variable is called Flag is :
> Once the limit for the subterms is determined the subterms are flagged with (by
> the function "flag_with") this limit.

Ok, fair enough.  But you should put this explanation of what it means
to be flagged in a comment somewhere in the code.

> 
> %------------------------------------------------------------------------------%
> 
> > + % Rounding up the Lines and subtracting works because we assume 
> > + % that each argument is a differnet line or they are all on 
> > + % the same line. But this requires you to determine which case 
> > + % likely to happen before hand. For example if a term is to be 
> > + % on one line, you should do subtract_size_count(size_count(0, 
> > + % LineLength), size_count(0, arglength)) rather than 
> > + % subtract_size_count(size_count(1, 0), size_count(0, arglength)). 
> 
> Why not detect this situation in this code? You have access to the line 
> width (in the measure_params), so you should be able to change an argument 
> of the form size_count(1, 0) into the required form. Is there any reason 
> why this wouldn't work? 
> 
> > +:- func subtract_size_count(size_count, size_count,measure_params) = size_count.
> 
> The reason that this situation cannot be detected in this code is:
> A term can be printed on a single line only if, all of it's
> arguments can be printed on the same line. And you cannot determine
> which case is likely to happen in this code using the information
> it has. Therefore size_count_split determines which case is true
> (and changes the limit accordingly).
> 
> %------------------------------------------------------------------------------%
> 
> ################################################################################
> # 			The Following is the Relative Diff 		       #
> ################################################################################
> 
> --- /home/stude/s/sthur/Review/mercury/browser/sized_pretty.m	Tue Jan 23 12:03:21 2001
> +++ /home/stude/s/sthur/ws1/mercury/browser/sizepretty.m	Tue Jan 23 15:58:16 2001

This is a reverse diff!  Oh well, I'll just have to review it standing
on my head. (-:

> @@ -1,27 +1,13 @@
> -%---------------------------------------------------------------------------%
> -% Copyright (C) 1998-2001 The University of Melbourne.

The year should be just 2001 by itself.

> -% This file may only be copied under the terms of the GNU Library General
> -% Public License - see the file COPYING.LIB in the Mercury distribution.
> -%---------------------------------------------------------------------------%
> -
> -% sized_pretty-	When printing a term during debugging this module allows
> -%		the user to put a limit on the size of the term displayed.
> -%               This limit is specified by setting the number of lines you 
> -%               want and the width of these lines. 
> +% How to use sizepretty.m
> +% 1. Pass a term(in univ type), a linewidth(by measure_params(LineWidth)), 
> +%    a Limit(size_count(NO.of.Lines, NO.of.Chars)) to annotate_with_size
> +%    and you will recieve a size_annotated term.
>  %
> +% 2. Pass this Size annotated term to my_to_doc, which returns a 'doc' type
> +%    value.
>  %
> -% author: sthur
> -%
> -% How to use sized_pretty.m :
> -% ---------------------------
> -%
> -% Call univ_to_string_line with the follwing variables:
> -% 	univ_to_string_line(Univ, LineWidth, Lines, String)
> -%		where Univ 	: is the Term (in univ type) you want to convert
> -%		      LineWidth : is the length of the lines
> -%		      Lines 	: is the number of lines you want the term to be
> -%		            	  printed on
> -%		      String	: output string
> +% 3. Pass this 'doc' type value to pprint__to_string along with the LineWidth
> +%    to receive a string which can be printed.
>  %
>  % EXAMPLES
>  % --------
> @@ -48,232 +34,198 @@
>  %		     "Level 2",
>  %		     small
>  %                    )).
> -%
> +/*
>  %------------------------------------------------------------------------------%
> -% Width = 18, Line(s) = 16
> -%
> -% big(
> -%   big(
> -%     big(
> -%       small, 
> -%       "Level 3", 
> -%       small), 
> -%     "Level 2", 
> -%     small), 
> -%   "Level 1", 
> -%   big(
> -%     big(
> -%       small, 
> -%       "Level 3", 
> -%       small), 
> -%     "Level 2", 
> -%     small))
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 16, Line(s) = 16
> -% 
> -% big(
> -%   big(
> -%     big/3, 
> -%     "Level 2", 
> -%     small), 
> -%   "Level 1", 
> -%   big(
> -%     big/3, 
> -%     "Level 2", 
> -%     small))
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 50, Line(s) = 4
> -% 
> -% big(
> -%   big(big/3, "Level 2", small), 
> -%  "Level 1", 
> -%   big(big/3, "Level 2", small))
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 56, Line(s) = 4
> -% 
> -% big(
> -%   big(big(small, "Level 3", small), "Level 2", small), 
> -%   "Level 1", 
> -%   big(big(small, "Level 3", small), "Level 2", small))
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 30, Line(s) = 5
> -% 
> -% big(big/3, "Level 1", big/3)
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 33, Line(s) = 5
> -% 
> -% big(
> -%   big(big/3, "Level 2", small), 
> -%   "Level 1", 
> -%   big(big/3, "Level 2", small))
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 75, Line(s) = 1
> -% 
> -% big(big(big/3, "Level 2", small), "Level 1", big(big/3, "Level 2", small))
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 20, Line(s) = 10
> -% 
> -% big(
> -%   big(
> -%     big/3, 
> -%     "Level 2", 
> -%     small), 
> -%   "Level 1", 
> -%   big(
> -%     big/3, 
> -%     "Level 2", 
> -%     small))
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 40, Line(s) = 10
> -% 
> -% big(
> -%   big(
> -%     big(small, "Level 3", small), 
> -%     "Level 2", 
> -%     small), 
> -%   "Level 1", 
> -%   big(
> -%     big(small, "Level 3", small), 
> -%     "Level 2", 
> -%     small))
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 29, Line(s) = 1
> -% 
> -% big(big/3, "Level 1", big/3)
> -% 
> -%------------------------------------------------------------------------------%
> -% Width = 20, Line(s) = 1
> -% 
> -% big/3
> -% 
> +Width = 16, Limit = size_count(16, 0)
> +
> +big(
> +  big(
> +    big(
> +      small, 
> +      "Level 3", 
> +      small), 
> +    "Level 2", 
> +    small), 
> +  "Level 1", 
> +  big(
> +    big(
> +      small, 
> +      "Level 3", 
> +      small), 
> +    "Level 2", 
> +    small))
> +
>  %------------------------------------------------------------------------------%
> +Width = 14, Limit = size_count(16, 0)
>  
> -:- module mdb__sized_pretty.
> +big(
> +  big(
> +    big/3, 
> +    "Level 2", 
> +    small), 
> +  "Level 1", 
> +  big(
> +    big/3, 
> +    "Level 2", 
> +    small))
>  
> -:- interface.
> +%------------------------------------------------------------------------------%
> +Width = 50, Limit = size_count(4, 0)
>  
> -:- import_module std_util, int, string.
> +big(
> +  big(big/3, "Level 2", small), 
> +  "Level 1", 
> +  big(big/3, "Level 2", small))
>  
> -	% This may throw an exception or cause a runtime abort if the term
> -	% in question has user-defined equality. 
> -	% The Limit is number of lines.
> -:- pred univ_to_string_line(univ::in, int::in, int::in, string::out) is det.
> +%------------------------------------------------------------------------------%
> +Width = 54, Limit = size_count(4, 0)
> +
> +big(
> +  big(big(small, "Level 3", small), "Level 2", small), 
> +  "Level 1", 
> +  big(big(small, "Level 3", small), "Level 2", small))
>  
>  %------------------------------------------------------------------------------%
> +Width = 29, Limit = size_count(5, 0)
>  
> -:- implementation.
> +big(big/3, "Level 1", big/3)
> +
> +%------------------------------------------------------------------------------%
> +Width = 31, Limit = size_count(5, 0)
>  
> -:- import_module list, require, assoc_list, pprint, bool.
> +big(
> +  big(big/3, "Level 2", small), 
> +  "Level 1", 
> +  big(big/3, "Level 2", small))
>  
> -:- type no_measure_params --->	no_measure_params.
> -:- type measure_params
> -	--->	measure_params(int).	% This parameter specifies Linewidth
> +%------------------------------------------------------------------------------%
> +Width = 74, Limit = size_count(2, 0)
> +
> +big(big(big/3, "Level 2", small), "Level 1", big(big/3, "Level 2", small))
> +
> +%------------------------------------------------------------------------------%
> +Width = 20, Limit = size_count(10, 0)
> +
> +big(
> +  big(
> +    big/3, 
> +    "Level 2", 
> +    small), 
> +  "Level 1", 
> +  big(
> +    big/3, 
> +    "Level 2", 
> +    small))
> +
> +%------------------------------------------------------------------------------%
> +Width = 40, Limit = size_count(10, 0)
> +
> +big(
> +  big(
> +    big(small, "Level 3", small), 
> +    "Level 2", 
> +    small), 
> +  "Level 1", 
> +  big(
> +    big(small, "Level 3", small), 
> +    "Level 2", 
> +    small))
> +
> +%------------------------------------------------------------------------------%
> +Width = 28, Limit = size_count(1, 0)
> +
> +big(big/3, "Level 1", big/3)
> +
> +%------------------------------------------------------------------------------%
> +Width = 20, Limit = size_count(1, 0)
> +
> +big/3
> +
> +%------------------------------------------------------------------------------%
> +*/
> +
> +:- module sizepretty.
> +
> +:- interface.
> +
> +:- import_module std_util, list, pprint, bool, int, string.
>  
> +:- type measure_params
> +	--->	measure_params
> +	;	measure_params(int).
>  
>  :- type maybe_deconstructed(T)
>  	--->	not_deconstructed
>  	;	deconstructed(
> -			string,		% Functor 
> -			int,		% Arity
> -			list(maybe(pair(T, size_annotated_term(T)))) % arguments
> +			string,
> +			int,
> +			list(maybe(pair(T, size_annotated_term(T))))  	
>  		).
>  
> -	% The exact type indicates the term has been fully deconstructed.
> -	% The at_least type indicates that the term has been deconstructed
> -	% upto the point where the specified limit was reached.
>  :- type size_annotated_term(T)
>  	--->	exact(
> -			univ,		% univ(Term)
> -			T,		% size of the term
> -			string,		% Functor
> -			int,		% Arity
> -			list(maybe(pair(T, size_annotated_term(T)))) % arguments
> +			univ,
> +			T,
> +			string,
> +			int,
> +			list(maybe(pair(T, size_annotated_term(T))))
>  		)
>  	;	at_least(
> -			univ,		% univ(Term)
> -			T,		% size of the term upto the point
> -					% where it's deconstructed
> +			univ,
> +			T,
>  			maybe_deconstructed(T)
>  		).
>  
> +:- type functor_count
> +	--->	functor_count(int).
> +
> +:- type char_count
> +	--->	char_count(int).
> +
> +:- type size_count
> +	--->	size_count(int, int).	
> +
>  :- typeclass measure(T) where [
> +	func add_measures(T, T, measure_params) = T is det,
> +	func subtract_measures(T, T, measure_params) = T is det,
> +	func compare_measures(T, T) = comparison_result is det,
>  	func max_measure(T, T) = T is det,
>  	func zero_measure = T is det,
> -	func compare_measures(T, T) = comparison_result is det
> -].
> -
> -:- typeclass measure_with_params(T, MeasureParams) <= measure(T) where [
> -	func add_measures(T, T, MeasureParams) = T is det,
> -	func subtract_measures(T, T, MeasureParams) = T is det,
> -
> -		% given a term, it's arity, and a limit, this method decides
> -		% the partial limit that each of the argument should be
> -		% given. It's arguments in order are term, measure parameter(s),
> -		% limit, arity, a flag, size of the Functor, partial limit,
> -		% adjusted limit, adjusted measure parameter(s).
> -		% Also a term is not deconstructed unless it has enough space
> -		% to print functor and the functors of it's arguments. But in
> -		% some cases this check is not needed that's why the booleen is
> -		% included.

Instead of these last two sentences, it would be better to say something like:

	% If the bool is `yes', we check that there is enough space to
	% print the functor and the functors of its arguments before
	% deconstructing the term.

> -	pred measured_split(univ::in, MeasureParams::in, T::in, int::in,
> -	     bool::in, T::out, maybe(T)::out, T::out, MeasureParams::out) is det
> +	pred measured_split(univ::in, measure_params::in, T::in, int::in,
> +	     bool::in, T::out, maybe(T)::out, T::out,measure_params::out) is det
>  		
>  ].
>  
> -%------------------------------------------------------------------------------%
> -	% When the space (to print the term) is given in number of lines there
> -	% is an inital check that has to be done. This is due to the fact that
> -	% size_count_split assumes that every term is part of a bigger term and
> -	% therefore assumes that a term will have a comma and a space after it.
> -	% This is not true for the biggest term (Head Term) therefore if the
> -	% Head Term is going to be printed on a single line then it should be
> -	% given a limit of character_count(LineWidth - 1) instead of
> -	% character_count(LineWidth - 3).
> -univ_to_string_line(Univ, LineWidth, Lines, String) :-
> -	Params = measure_params(LineWidth),
> -	deconstruct(univ_value(Univ), _, Arity, _),
> -	( 	Arity \= 0,
> -		Lines \= 0,
> -		(Lines - 1) // Arity = 0 
> -	->
> -		% "- 1" is to account for the newline character
> -		Limit = character_count(LineWidth - 1)
> -	;
> -		Limit = line_count(Lines)
> -	),
> -	annotate_with_size(Univ, Params, Limit, AnnotTerm),
> -	Doc = to_doc_sized(AnnotTerm),
> -	String = pprint__to_string(LineWidth, Doc).
> +:- instance measure(functor_count).
> +:- instance measure(char_count).
> +:- instance measure(size_count).
> +	
> +	% This may throw an exception or cause a runtime abort if the term
> +	% in question has user-defined equality.
> +:- pred annotate_with_size(univ::in, measure_params::in, T::in,
> +	size_annotated_term(T)::out) is det <= measure(T).
> +
> +	% A function to convert a size annotated term to a 'doc' type,
> +	% a type defined in pprint.m.
> +:- func my_to_doc(size_annotated_term(T)) = doc <= measure(T).
> +
> +:- implementation.
> +
> +:- import_module require, assoc_list.
>  
>  %------------------------------------------------------------------------------%
>  	% first_pass gives an idea of how much space each term takes
> -	% In this pass the space is unevenly distributed. First come first
> -	% served. And once the space runs out, the term is not deconstructed
> -	% further. 
> -	% In The Second pass the space is evenly distributed between
> -	% the terms and therefore the subterms are deconstructed evenly.
> -:- pred annotate_with_size(univ::in, MeasureParams::in, T::in,
> -	size_annotated_term(T)::out) is det
> -	<= measure_with_params(T, MeasureParams).
> -
> +	% (In this pass the space is unevenly distributed. First come first
> +	% served. In The Second pass the space is evenly distriduted between
> +	% the terms.
>  annotate_with_size(Univ, Params, Limit, Size2) :-
>  	first_pass(Univ, Params, Limit, Size1),
>  	second_pass(Size1, Params, Limit, Size2).
>  
>  %------------------------------------------------------------------------------%
>  	
> -:- pred first_pass(univ::in, MeasureParams::in, T::in,
> -	size_annotated_term(T)::out) is det
> -	<= measure_with_params(T, MeasureParams).
> +:- pred first_pass(univ::in, measure_params::in, T::in,
> +	size_annotated_term(T)::out) is det <= measure(T).
>  
>  first_pass(Univ, Params, Limit, Size) :-
>  	deconstruct(univ_value(Univ), Functor, Arity, Args),	
> @@ -299,9 +251,9 @@
>  %------------------------------------------------------------------------------%
>  	% annotating the arguments.
>  :- pred annotate_args_with_size(assoc_list(maybe(T), univ)::in,
> -	MeasureParams::in, T::in, T::in, T::out, bool::in, bool::out,
> +	measure_params::in, T::in, T::in, T::out, bool::in, bool::out,
>  	list(maybe(pair(T, size_annotated_term(T))))::out)
> -	is det <= measure_with_params(T, MeasureParams).
> +	is det <= measure(T).
>  
>  annotate_args_with_size([], _, _, SoFar, SoFar, Exact, Exact, []).
>  annotate_args_with_size([Flag - Arg | FlaggedArgs], Params, Limit,
> @@ -339,7 +291,7 @@
>  	).
>  
>  %------------------------------------------------------------------------------%
> -	% Annotates the arguments with zero limit.
> +
>  :- pred annotate_args_with_zero_size(assoc_list(maybe(T), univ)::in, T::in,
>  	list(maybe(pair(T, size_annotated_term(T))))::out) is det <= measure(T).
>  
> @@ -377,53 +329,46 @@
>  	% the other terms which could take up more than their share.
>  	% If a term can be fully printed within the given space,
>  	% ("exact" type) then the Term is not altered.
> -:- pred second_pass(size_annotated_term(T)::in, MeasureParams::in, T::in,
> -	size_annotated_term(T)::out) is det 
> -	<= measure_with_params(T, MeasureParams).
> +:- pred second_pass(size_annotated_term(T)::in, measure_params::in, T::in,
> +	size_annotated_term(T)::out) is det <= measure(T).
>  
>  second_pass(OldSizeTerm, Params, Limit, NewSizeTerm) :-
> -	(
> -    		OldSizeTerm = exact(_Univ, _Size, _, _Arity, _MaybeArgs),
> -		NewSizeTerm = OldSizeTerm
> -	;
> -    		OldSizeTerm = at_least(_Univ, _Size, not_deconstructed),
> -		NewSizeTerm = OldSizeTerm
> -	;
> -    		OldSizeTerm = at_least(Univ, _Size, deconstructed(Functor, 
> -			Arity,MaybeArgs)),
> -		measured_split(Univ, Params, Limit, Arity, yes, FSize, Flag,
> -			NewLimit, NewParams),
> -		( if Flag = yes(X) then
> -	    		ArgLimit = X,
> -	    		check_args(NewParams, MaybeArgs, ArgLimit, Passed, 
> -				Used),
> -			LeftOver = subtract_measures(NewLimit, Used, Params),
> -	    		measured_split(Univ, Params, LeftOver, Arity - Passed, 
> -				no, _, Flag2, _, _),
> -	    		( if Flag2 = yes(Y) then
> -	        		SplitLimit = Y,
> -	        		process_args(NewParams, MaybeArgs, ArgLimit, 
> -					SplitLimit, NewArgs, NewSize0),
> -				NewSize = add_measures(FSize, NewSize0, 
> -					NewParams),
> -				Result0 = list__map(check_if_exact, NewArgs),
> -    				list__remove_adjacent_dups(Result0, Result),
> -				( Result = [yes] ->
> -					NewSizeTerm = exact(Univ, NewSize, 
> -						Functor, Arity, NewArgs) 	
> -	        		;
> -					NewSizeTerm = at_least(Univ, NewSize, 
> -						deconstructed(Functor, Arity, 
> -						NewArgs))
> -				)
> -	    		else
> -	        		NewSizeTerm = at_least(Univ, FSize, 
> -					not_deconstructed)
> -	    		)
> -		else
> -	    	NewSizeTerm = at_least(Univ, FSize, not_deconstructed)
> +    if OldSizeTerm = exact(_Univ, _Size, _, _Arity, _MaybeArgs) then
> +	NewSizeTerm = OldSizeTerm
> +    else if OldSizeTerm = at_least(_Univ, _Size, not_deconstructed) then
> +	NewSizeTerm = OldSizeTerm
> +    else if OldSizeTerm = at_least(Univ, _Size, deconstructed(Functor, Arity,
> +	MaybeArgs)) then
> +	measured_split(Univ, Params, Limit, Arity, yes, FSize, Flag, NewLimit, 
> +		NewParams),
> +	( if Flag = yes(X) then
> +	    ArgLimit = X,
> +	    check_args(NewParams, MaybeArgs, ArgLimit, 0, Passed, 
> +	   	zero_measure, Used),
> +	    measured_split(Univ, Params, subtract_measures(NewLimit, Used, 
> +	    	Params), Arity-Passed, no, _, Flag2, _, _),
> +	    ( if Flag2 = yes(Y) then
> +	        SplitLimit = Y,
> +	        process_args(NewParams, MaybeArgs, ArgLimit, SplitLimit, 
> +			NewArgs, NewSize0),
> +		NewSize = add_measures(FSize, NewSize0, NewParams),
> +		Result0 = list__map(check_if_exact, NewArgs),
> +    		list__remove_adjacent_dups(Result0, Result),
> +		( Result = [yes] ->
> +			NewSizeTerm = exact(Univ, NewSize, Functor, 
> +				Arity, NewArgs) 	
> +	        ;
> +			NewSizeTerm = at_least(Univ, NewSize, 
> +				deconstructed(Functor, Arity, NewArgs))
>  		)
> -	).
> +	    else
> +	        NewSizeTerm = at_least(Univ, FSize, not_deconstructed)
> +	    )
> +	else
> +	    NewSizeTerm = at_least(Univ, FSize, not_deconstructed)
> +	)
> +    else
> +    	error("Incorrect type of Size Annotated Term").
>  	
>  %------------------------------------------------------------------------------%
>  	% Given a list of size annotated terms(ie arguments) and a
> @@ -431,29 +376,26 @@
>  	% "Used". Where "Passed" represents the number of terms that
>  	% obey the Limit and are fully represented("exact") and "Used"
>  	% represents the space that these terms take up.
> -:- pred check_args(MeasureParams::in, list(maybe(pair(T, size_annotated_term(T)
> -	)))::in, T::in, int::out, T::out) is det

It would probably make sense to use an equivalence type, eg:

	:- type size_annotated_args(T) ==
			list(maybe(pair(T, size_annotated_term(T)))).

This would make the code a bit more readable in a few places.

> -	<= measure_with_params(T, MeasureParams).
> -
> -check_args(_, [], _, 0, zero_measure).
> -check_args(Params, [HeadArg | Rest], ArgLimit, Passed, Used) :-
> -	if HeadArg = yes(X) then
> -		X = _ - STerm,
> -		Size = extract_size_from_annotation(STerm), 
> -		( if STerm = exact(_, _, _, _, _) then
> -	    		( if compare_measures(ArgLimit, Size) = (<) then
> -	    			check_args(Params, Rest, ArgLimit, Passed, Used)
> -	    		else
> -	    			Passed = 1 + PassedRest,
> -				Used = add_measures(UsedRest, Size, Params),
> -	    			check_args(Params, Rest, ArgLimit, PassedRest, 
> -					UsedRest)
> -	    		)
> -		else
> -	    		check_args(Params, Rest, ArgLimit, Passed, Used)
> -		)
> -    	else
> -		check_args(Params, Rest, ArgLimit, Passed, Used).
> +:- pred check_args(measure_params::in, list(maybe(pair(T, size_annotated_term(T)
> +	)))::in, T::in, int::in, int::out, T::in, T::out) is det <= measure(T).
> +
> +check_args(_, [], _, Passed0, Passed0, Used0, Used0).
> +check_args(Params, [HeadArg | Rest], ArgLimit, Passed0, Passed, Used0, Used) :-
> +    if HeadArg = yes(X) then
> +	X = _-STerm,
> +	Size = extract_size_from_annotation(STerm), 
> +	( if STerm = exact(_, _, _, _, _) then
> +	    ( if compare_measures(ArgLimit, Size) = (<) then
> +	    	check_args(Params, Rest, ArgLimit, Passed0, Passed, Used0, Used)
> +	    else
> +	    	check_args(Params, Rest, ArgLimit, Passed0+1, Passed, 
> +				add_measures(Used0, Size, Params), Used)
> +	    )
> +	else
> +	    check_args(Params, Rest, ArgLimit, Passed0, Passed, Used0, Used)
> +	)
> +    else
> +	check_args(Params, Rest, ArgLimit, Passed0, Passed, Used0, Used).
>  
>  %------------------------------------------------------------------------------%
>  	% This predicate accepts a list of size annotated terms(paired
> @@ -462,95 +404,95 @@
>  	% but the terms which do not obey the limit or not fully 
>  	% represented would be annoted again with a new limit
>  	% (SplitLimit). The rest of the terms are left alone.
> -:- pred process_args(MeasureParams::in, 
> +:- pred process_args(measure_params::in, 
>  	list(maybe(pair(T, size_annotated_term(T))))::in, T::in, T::in, 
>  	list(maybe(pair(T, size_annotated_term(T))))::out, T::out)
> -	is det <= measure_with_params(T, MeasureParams).
> +	is det <= measure(T).
>  
>  process_args(_, [], _, _, [], zero_measure).
>  process_args(Params, [HeadArg | Rest], ArgLimit, SplitLimit, 
>  		[NewHeadArg | NewRest], SizeOut) :-
> -    	( if HeadArg = yes(X) then
> -		X = _ - STerm,
> -		Size = extract_size_from_annotation(STerm), 
> -        	Univ = extract_univ_from_annotation(STerm), 
> -		( 
> -			STerm = exact(_, _, _, _, _),
> -	    		(
> -				compare_measures(ArgLimit, Size) = (>)
> -			;
> -	    			compare_measures(ArgLimit, Size) = (=)
> -			)
> -		->
> -			NewHeadArg = HeadArg
> -		;
> -			NewHeadArg = yes(pair(SplitLimit, NewSTerm)),
> -			annotate_with_size(Univ, Params, SplitLimit, NewSTerm)
> -		)
> -    	else
> -		NewHeadArg = no
> -    	),
> -    	( NewHeadArg = yes(_ - Term) ->
> -		NewSize = extract_size_from_annotation(Term),
> -		SizeOut = add_measures(NewSize, RestSize, Params)
> -    	;
> -		SizeOut = RestSize
> -    	),
> -    	process_args(Params, Rest, ArgLimit, SplitLimit, NewRest, RestSize).
> +    ( if HeadArg = yes(X) then
> +	X = _-STerm,
> +	Size = extract_size_from_annotation(STerm), 
> +        Univ = extract_univ_from_annotation(STerm), 
> +	( if STerm = exact(_, _, _, _, _) then
> +	    ( if compare_measures(ArgLimit, Size) = (<) then
> +		NewHeadArg = yes(pair(SplitLimit, NewSTerm)),
> +		annotate_with_size(Univ, Params, SplitLimit, NewSTerm)
> +	    else
> +		NewHeadArg = HeadArg
> +	    )
> +	else
> +	    NewHeadArg = yes(pair(SplitLimit, NewSTerm)),
> +	    annotate_with_size(Univ, Params, SplitLimit, NewSTerm)
> +	)
> +    else
> +	NewHeadArg = no
> +    ),
> +    ( NewHeadArg = yes(_-Term) ->
> +	NewSize = extract_size_from_annotation(Term),
> +	SizeOut = add_measures(NewSize, RestSize, Params)
> +    ;
> +	SizeOut = RestSize
> +    ),
> +    process_args(Params, Rest, ArgLimit, SplitLimit, NewRest, RestSize).
>  
>  %------------------------------------------------------------------------------%
>  	% checking if an size-annotated arg is an exact type (fully represented)
>  :- func check_if_exact(maybe(pair(T, size_annotated_term(T)))) = bool.
>  
>  check_if_exact(no) = no.
> -check_if_exact(yes(_ - Term)) = Result:-
> -	(
> -		Term = exact(_, _, _, _, _),
> +check_if_exact(yes(_-Term)) = Result:-
> +	( Term = exact(_, _, _, _, _) ->
>  		Result = yes
>  	;
> -		Term = at_least(_, _, _),
>  		Result = no
>  	).	
>  
>  %------------------------------------------------------------------------------%
> -	% A function to convert a size annotated term to a 'doc' type,
> -	% a type defined in pprint.m.
> -:- func to_doc_sized(size_annotated_term(T)) = doc.
> -
> -to_doc_sized(at_least(Univ, _, not_deconstructed)) = Doc :-
> +	% Converting size-annotated terms to 'doc' type
> +my_to_doc(at_least(Univ, _, not_deconstructed)) = Doc :-
>  	deconstruct(univ_value(Univ), Functor, Arity, _Args),
>  	Doc = text(Functor) `<>` text("/") `<>` poly(i(Arity)).
>  
> -to_doc_sized(at_least(_, _, deconstructed(Functor, Arity, MaybeArgs))) = Doc :-
> -	Doc = to_doc_sized_2(Functor, Arity, MaybeArgs).
> +my_to_doc(at_least(_, _, deconstructed(Functor, Arity, MaybeArgs))) = Doc :-
> +	Doc = my_to_doc2(Functor, Arity, MaybeArgs).
>  
> -to_doc_sized(exact(_, _, Functor, Arity, MaybeArgs)) = Doc :-
> -	Doc = to_doc_sized_2(Functor, Arity, MaybeArgs).
> +my_to_doc(exact(_, _, Functor, Arity, MaybeArgs)) = Doc :-
> +	Doc = my_to_doc2(Functor, Arity, MaybeArgs).
>  
>  %------------------------------------------------------------------------------%
>  	% Assumes that every argument must be on a different line
>  	% or all of them should be on the same line.
> -:- func to_doc_sized_2(string, int, 
> -	list(maybe(pair(T, size_annotated_term(T))))) = doc.
> +:- func my_to_doc2(string, int, list(maybe(pair(T, size_annotated_term(T))))) 
> +	= doc <= measure(T).
>  
> -to_doc_sized_2(Functor, _Arity, []) = text(Functor).
> +my_to_doc2(Functor, _Arity, []) = text(Functor).
>  
> -to_doc_sized_2(Functor, Arity, [HeadArg|Tail]) = Doc :-
> -    	Args = list__map(handle_arg, [HeadArg|Tail]),
> -    	list__remove_adjacent_dups(Args, NewArgs),
> -    	( NewArgs \= [nil] -> 
> -        	Doc = text(Functor) `<>` parentheses(group(nest(2, line `<>` 
> -			separated(id,comma_space_line, Args))))
> -    	;
> -        	Doc = text(Functor) `<>` text("/") `<>` poly(i(Arity))
> -    	).
> +my_to_doc2(Functor, Arity, [HeadArg|Tail]) = Doc :-
> +    Args = list__map(handleArg, [HeadArg|Tail]),
> +    list__remove_adjacent_dups(Args, NewArgs),
> +    ( NewArgs \= [text("*")] -> 
> +        (Doc = text(Functor) `<>`
> +	      parentheses(
> +	                 group(
> +	                      nest(2,
> +	                          line `<>` separated(id,comma_space_line, Args)
> +	                          )
> +	                      )
> +	                 )
> +	)
> +    ;
> +        Doc = text(Functor) `<>` text("/") `<>` poly(i(Arity))
> +    ).
>  	
>  %------------------------------------------------------------------------------%
>  
> -:- func handle_arg(maybe(pair(T,size_annotated_term(T)))) = doc.
> +:- func handleArg(maybe(pair(T,size_annotated_term(T)))) = doc <= measure(T).
>  
> -handle_arg(yes(_ - Arg_Term)) = to_doc_sized(Arg_Term). 
> -handle_arg(no) = nil.
> +handleArg(yes(_ - Arg_Term)) = my_to_doc(Arg_Term). 
> +handleArg(no) = text("*").
>  
>  %------------------------------------------------------------------------------%
>  	% A predicate that creates an associated list of Univ and their
> @@ -565,16 +507,13 @@
>  	% functor_count is a representation where the size of a term
>  	% is measured by the number of function symbols.
>  
> -:- type functor_count
> -	--->	functor_count(int). 	% No of function symbols
> -
>  :- func add_functor_count(functor_count, functor_count, 
> -	no_measure_params) = functor_count.
> +	measure_params) = functor_count.
>  
>  add_functor_count(functor_count(A), functor_count(B), _) = functor_count(A + B).
>  
>  :- func subtract_functor_count(functor_count, functor_count, 
> -	no_measure_params) = functor_count.
> +	measure_params) = functor_count.
>  
>  subtract_functor_count(functor_count(A), functor_count(B), _) =
>  	functor_count(A - B).
> @@ -593,12 +532,13 @@
>  
>  zero_functor_count = functor_count(0).
>  	
> -:- pred functor_count_split(univ::in, no_measure_params::in, functor_count::in,
> +	% Refer to size_count_split for comments.
> +:- pred functor_count_split(univ::in, measure_params::in, functor_count::in,
>  	int::in, bool::in, functor_count::out, maybe(functor_count)::out,
> -	functor_count::out, no_measure_params::out) is det.
> +	functor_count::out, measure_params::out) is det.
>  
> -functor_count_split(_, Params, functor_count(Limit), Arity, _, functor_count(1),
> -		Flag, functor_count(Limit), Params) :-
> +functor_count_split(_, X, functor_count(Limit), Arity, _, functor_count(1),
> +		Flag, functor_count(Limit), X) :-
>  	( Arity = 0 ->
>  		Flag = no
>  	;
> @@ -611,31 +551,24 @@
>  	).
>  
>  :- instance measure(functor_count) where [
> -	func(compare_measures/2) is compare_functor_count,
> -	func(max_measure/2) is max_functor_count,
> -	func(zero_measure/0) is zero_functor_count
> -].
> -
> -:- instance measure_with_params(functor_count, no_measure_params) where [
>  	func(add_measures/3) is add_functor_count,
>  	func(subtract_measures/3) is subtract_functor_count,
> +	func(compare_measures/2) is compare_functor_count,
> +	func(max_measure/2) is max_functor_count,
> +	func(zero_measure/0) is zero_functor_count,
>  	pred(measured_split/9) is functor_count_split
>  ].
>  
> -
>  %------------------------------------------------------------------------------%
>  	% char_count is a representation where the size of a term is
>  	% measured by the number of characters.
>  
> -:- type char_count
> -	--->	char_count(int).	% No of characters
> -
> -:- func add_char_count(char_count, char_count, no_measure_params) = char_count.
> +:- func add_char_count(char_count, char_count, measure_params) = char_count.
>  
>  add_char_count(char_count(A), char_count(B), _) = char_count(A + B).
>  
>  :- func subtract_char_count(char_count, char_count, 
> -	no_measure_params) = char_count.
> +	measure_params) = char_count.
>  
>  subtract_char_count(char_count(A), char_count(B), _) =
>  	char_count(A - B).
> @@ -654,12 +587,13 @@
>  
>  zero_char_count = char_count(0).
>  
> -:- pred char_count_split(univ::in, no_measure_params::in, char_count::in,
> +	% Refer to size_count_split for comments.
> +:- pred char_count_split(univ::in, measure_params::in, char_count::in,
>  	int::in, bool::in, char_count::out, maybe(char_count)::out,
> -	char_count::out, no_measure_params::out) is det.
> +	char_count::out, measure_params::out) is det.
>  
> -char_count_split(Univ, Params, char_count(Limit), Arity, Check, 
> -		char_count(FunctorSize), Flag, char_count(Limit), Params) :-
> +char_count_split(Univ, X, char_count(Limit), Arity, Check, 
> +		char_count(FunctorSize), Flag, char_count(Limit), X) :-
>  	deconstruct(univ_value(Univ), Functor, _, Args),
>  	( Check = yes ->
>  		get_arg_length(Args, TotalLength, _)
> @@ -679,111 +613,92 @@
>  	).
>  
>  :- instance measure(char_count) where [
> -        func(compare_measures/2) is compare_char_count,
> -        func(max_measure/2) is max_char_count,
> -        func(zero_measure/0) is zero_char_count
> -].
> -
> -:- instance measure_with_params(char_count, no_measure_params) where [
>          func(add_measures/3) is add_char_count,
>          func(subtract_measures/3) is subtract_char_count,
> +        func(compare_measures/2) is compare_char_count,
> +        func(max_measure/2) is max_char_count,
> +        func(zero_measure/0) is zero_char_count,
>          pred(measured_split/9) is char_count_split
>  ].
>  
>  %------------------------------------------------------------------------------%
>  	% size_count is representation where the size of a term is
> -	% measured by number of lines or number of characters.
> -
> -:- type size_count
> -	--->	line_count(int)		% no of lines
> -	;	character_count(int).	% no of characters
> +	% measured by number of lines and number of characters.
>  
>  :- func add_size_count(size_count, size_count, measure_params) = size_count.
>  
> -add_size_count(character_count(A), character_count(B), Params) = Result :-
> -	Params = measure_params(LineWidth),
> -	CharSum = A + B,
> -	( CharSum > LineWidth ->
> -		Result = line_count(1)
> -	;
> -		Result = character_count(CharSum)
> -	).
> -
> -add_size_count(character_count(A), line_count(B), _) = Result :-
> -	( A > 0 -> 
> -		Result = line_count(B + 1)
> +add_size_count(size_count(L1, C1), size_count(L2, C2), 
> +		Params) = size_count(Line, Char) :-
> +	( Params = measure_params(W) ->
> +		LineWidth = W
>  	;
> -		Result = line_count(B)
> -	).
> -
> -add_size_count(line_count(A), character_count(B), _) = Result :-
> -	( B > 0 -> 
> -		Result = line_count(A + 1)
> -	;
> -		Result = line_count(A)
> +		LineWidth = 80
> +	),
> +	( (L1 > 0 ; L2 > 0) ->
> +		( C1 > 0 ->
> +			R1 = L1 + 1
> +		;
> +			R1 = L1
> +		),
> +		( C2 > 0 ->
> +			R2 = L2 +1
> +		;	
> +			R2 = L2
> +		),
> +		Line = R1 + R2,
> +		Char = 0
> +	;
> +		( (C1 + C2) > LineWidth ->
> +			Line = 1,
> +			Char = 0
> +		;
> +			Line = 0,
> +			Char = C1 + C2
> +		)
>  	).
> -
> -add_size_count(line_count(A), line_count(B), _) = line_count(A + B).
> -
> +		
>  	% Rounding up the Lines and subtracting works because we assume
> -	% that each argument is a different line or they are all on 
> +	% that each argument is a differnet line or they are all on 
>  	% the same line. But this requires you to determine which case
>  	% likely to happen before hand. For example if a term is to be
>  	% on one line, you should do subtract_size_count(size_count(0, 
>  	% LineLength), size_count(0, arglength)) rather than
>  	% subtract_size_count(size_count(1, 0), size_count(0, arglength)).
> -	% The reason that this situation cannot be detected in this code is:
> -	% A term can be printed on a single line only if, all of it's 
> -	% arguments can be printed on the same line. And you cannot determine
> -	% which case is likely to happen in this code using the information 
> -	% it has. Therefore size_count_split determines which case is true 
> -	% (and changes the limit accordingly).
>  :- func subtract_size_count(size_count, size_count,measure_params) = size_count.
>  
> -subtract_size_count(character_count(A), character_count(B), _) = Result :-
> -	CharDiff = A - B,
> -	( CharDiff < 0 ->
> -		Result = character_count(0)
> -	;
> -		Result = character_count(CharDiff)
> -	).
> -
> -subtract_size_count(character_count(A), line_count(B), _) = Result :-
> -	( B = 0 -> 
> -		Result = character_count(A)
> -	;
> -		Result = character_count(0)
> -	).
> -
> -subtract_size_count(line_count(A), character_count(B), _) = Result :-
> -	( B = 0 -> 
> -		Result = line_count(A)
> -	;
> -		( A - 1 >= 0 ->
> -			Result = line_count(A - 1)
> +subtract_size_count(size_count(L1, C1), size_count(L2, C2), _Params) 
> +		= size_count(Line, Char) :-
> +	( (L1 > 0 ; L2 > 0) ->
> +		( C1 > 0 ->
> +			R1 = L1 + 1
>  		;
> -			Result = line_count(0)
> -		)
> -	).
> -
> -subtract_size_count(line_count(A), line_count(B), _) = Result :-
> -	( A - B >= 0 ->
> -		Result = line_count(A - B)
> +			R1 = L1
> +		),
> +		( C2 > 0 ->
> +			R2 = L2 +1
> +		;	R2 = L2
> +		),
> +		Line0 = R1 - R2,
> +		Char0 = 0
>  	;
> -		Result = line_count(0)
> +		Line0 = 0,
> +		Char0 = C1 - C2
> +	),
> +	( (Line0 < 0 ; Char0 < 0) ->
> +		Line = 0,
> +		Char = 0
> +	;
> +		Line = Line0,
> +		Char = Char0
>  	).
>  
>  :- func compare_size_count(size_count, size_count) = comparison_result.
>  
> -compare_size_count(character_count(C1), character_count(C2)) = R :-
> -	compare(R, C1, C2).
> -
> -compare_size_count(character_count(_), line_count(_)) = (<).
> -
> -compare_size_count(line_count(_), character_count(_)) = (>).
> -
> -compare_size_count(line_count(L1), line_count(L2)) = R :-
> -	compare(R, L1, L2).
> +compare_size_count(size_count(L1, C1), size_count(L2, C2)) = R :-
> +	L1 = L2 ->
> +		compare(R, C1, C2)
> +	;
> +		compare(R, L1, L2).
>  
>  :- func max_size_count(size_count, size_count) = size_count.
>  
> @@ -796,81 +711,77 @@
>  
>  :- func zero_size_count = size_count.
>  
> -zero_size_count = character_count(0).
> +zero_size_count = size_count(0, 0).
>  
> -	% We assume that all arguments have to be on separate lines, or 
> -	% the whole term should be printed on a single line.
> +	% This code divides up the Limit into smaller Limits for
> +	% the terms's arguments. We assume that all arguments have
> +	% to be on separte lines, or the whole term should be printed
> +	% on a single line.
> +	% I have modified this code so that a term is not deconstructed
> +	% unless it has enough space to print functor and the functors
> +	% of it's arguments. But in some cases this check is not needed
> +	% that's why the booleen is included.
>  :- pred size_count_split(univ::in, measure_params::in, size_count::in,
>  	int::in, bool::in, size_count::out, maybe(size_count)::out,
>  	size_count::out, measure_params::out) is det.
>  
>  size_count_split(Univ, Params, Limit, Arity, Check, FunctorSize, 
>  		Flag, NewLimit, NewParams) :-
> -	Params = measure_params(LineWidth),
> -    	deconstruct(univ_value(Univ), Functor, ActualArity, Args),
> -    	FSize = string__length(Functor) + 2*(ActualArity),
> -    	( Check = yes ->
> -    		get_arg_length(Args, TotalLength, MaxArgLength),
> -		int__max(MaxArgLength, (string__length(Functor) + 1), MaxLength)
> -    	;
> -    		TotalLength = 0,
> -		MaxLength = 0
> -    	), 
> -    	( 
> -		Arity = 0 
> -	->
> -		Flag = no,
> -    		FunctorSize = character_count(FSize),
> -		NewLimit = Limit,
> -		NewParams = Params
> -    	;
> -		(
> -			Limit = line_count(LineLimit),
> -			(LineLimit >= (Arity + 1), 
> -			(LineWidth - 2) >= MaxLength) 
> -		->
> -			Line = (LineLimit - 1) // Arity,
> -			Flag = yes(line_count(Line)),
> -			FunctorSize = line_count(1),
> -	    		NewLimit = Limit,
> -	    		NewParams = measure_params(LineWidth - 2)
> -		;
> -			Limit = line_count(LineLimit),
> -			LineLimit > 0, 
> -			LineWidth - 3 >= (FSize + TotalLength) 
> -		->
> -	    		Char = (LineWidth - 3 - FSize + Arity - 1) // Arity ,
> -	    		Flag = yes(character_count(Char)),
> -	    		FunctorSize = character_count(FSize),
> -	    		NewLimit = character_count(LineWidth - 3),
> -	    		NewParams = Params
> -   		;
> -			Limit = character_count(CharLimit),
> -			CharLimit >= (FSize + TotalLength)
> -		->
> -	   		Char = (CharLimit - FSize + Arity - 1)// Arity,
> -	   		Flag = yes(character_count(Char)),
> -	   		FunctorSize = character_count(FSize),
> -	   		NewLimit = Limit,
> -	   		NewParams = Params
> -		;
> -	   		Flag = no, 
> -	   		FunctorSize = 
> -				character_count(string__length(Functor) + 2),
> -	   		NewLimit = Limit, 
> -	   		NewParams = Params
> -		)
> -	).
> +    ( Params = measure_params(X) ->
> +        LineWidth = X	
> +    ;
> +	LineWidth = 80
> +    ),
> +    deconstruct(univ_value(Univ), Functor, ActualArity, Args),
> +    FSize = string__length(Functor) + 2*(ActualArity),
> +    ( Check = yes ->
> +    	get_arg_length(Args, TotalLength, MaxLength)
> +    ;
> +    	TotalLength = 0,
> +	MaxLength = 0
> +    ), 
> +    ( Arity = 0 ->
> +	Flag = no,
> +    	FunctorSize = size_count(0, FSize),
> +	NewLimit = Limit,
> +	NewParams = Params
> +    ;
> +	Limit = size_count(LineLimit, CharLimit),
> +	( if (LineLimit >= (Arity + 1), (LineWidth - 2) >= MaxLength) then
> +	    Line = (LineLimit - 1) // Arity,
> +	    Char = 0,
> +	    Flag = yes(size_count(Line, Char)),
> +	    FunctorSize = size_count(1, 0),
> +	    NewLimit = Limit,
> +	    NewParams = measure_params(LineWidth - 2)
> +	else if (LineLimit > 0, LineWidth >= (FSize + TotalLength)) then
> +	    Line = 0,
> +	    Char = (LineWidth - FSize + Arity - 1) // Arity ,
> +	    Flag = yes(size_count(Line, Char)),
> +	    FunctorSize = size_count(0, FSize),
> +	    NewLimit = size_count(0, LineWidth),
> +	    NewParams = Params
> +   	else if (CharLimit >= (FSize + TotalLength)) then
> +	   Line = 0,	
> +	   Char = (CharLimit - FSize + Arity - 1)// Arity,
> +	   Flag = yes(size_count(Line, Char)),
> +	   FunctorSize = size_count(0, FSize),
> +	   NewLimit = Limit,
> +	   NewParams = Params
> +	else
> +	   Flag = no, 
> +	   FunctorSize = size_count(0, string__length(Functor)+2),
> +	   NewLimit = Limit, 
> +	   NewParams = Params
> +	) 	
> +    ).
>  
>  :- instance measure(size_count) where [
> -	func(compare_measures/2) is compare_size_count,
> -	func(max_measure/2) is max_size_count,
> -	func(zero_measure/0) is zero_size_count
> -].
> -
> -:- instance measure_with_params(size_count, measure_params) where [
>  	func(add_measures/3) is add_size_count,
>  	func(subtract_measures/3) is subtract_size_count,
> +	func(compare_measures/2) is compare_size_count,
> +	func(max_measure/2) is max_size_count,
> +	func(zero_measure/0) is zero_size_count,
>  	pred(measured_split/9) is size_count_split
>  ].
>  
> @@ -883,11 +794,6 @@
>  get_arg_length([], 0, 0).
>  get_arg_length([HeadUniv | Rest], TotalLength, MaxLength) :-
>  	deconstruct(univ_value(HeadUniv), Functor, Arity, _),
> -	( Rest = [] ->
> -		Correction = 2
> -	;
> -		Correction = 3
> -	),
>  	( Arity = 0 -> 
>  		Length = string__length(Functor)
>  	;
> @@ -897,7 +803,7 @@
>  		Length = string__length(Functor) + 2
>  	),
>  	TotalLength = Length + RestTotalLength,
> -	int__max((Length + Correction), RestMaxLength, MaxLength),
> +	int__max(Length, RestMaxLength, MaxLength),
>  	get_arg_length(Rest, RestTotalLength, RestMaxLength).
>  
>  %------------------------------------------------------------------------------%
> --- /home/stude/s/sthur/Review/mercury/browser/browse.m	Tue Jan 23 14:43:47 2001
> +++ /home/stude/s/sthur/ws1/mercury/browser/browse.m	Tue Jan 23 15:55:39 2001
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 1998-2001 The University of Melbourne.
> +% Copyright (C) 1998-2000 The University of Melbourne.
>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -82,9 +82,9 @@
>  %---------------------------------------------------------------------------%
>  :- implementation.
>  
> -:- import_module mdb__parse, mdb__util, mdb__frame, mdb__sized_pretty.
> +:- import_module mdb__parse, mdb__util, mdb__frame.
>  :- import_module string, list, parser, require, std_util, int, char, pprint.
> -:- import_module bool.
> +:- import_module bool, sizepretty.
>  
>  %---------------------------------------------------------------------------%
>  %
> @@ -317,8 +317,7 @@
>  "\th              -- help\n",
>  "\n",
>  "-- settings:\n",
> -"--    size; depth; path; format (flat raw_pretty verbose pretty); width; ",
> -"lines\n",
> +"--    size; depth; path; format (flat pretty verbose); width; lines\n",
>  "--    Paths can be Unix-style or SICStus-style: /2/3/1 or ^2^3^1\n",
>  "\n"],
>  		HelpMessage) },
> @@ -343,14 +342,14 @@
>  			{ Format = flat },
>  			portray_flat(Debugger, SubUniv, Params)
>  		;
> -			{ Format = raw_pretty },
> -			portray_raw_pretty(Debugger, SubUniv, Params)
> +			{ Format = pretty },
> +			portray_pretty(Debugger, SubUniv, Params)
>  		;
>  			{ Format = verbose },
>  			portray_verbose(Debugger, SubUniv, Params)
>  		;
> -			{ Format = pretty },
> -			portray_pretty(Debugger, SubUniv, Params)
> +			{ Format = newpretty },
> +			portray_newpretty(Debugger, SubUniv, Params)
>  		)
>  	;
>  		write_string_debugger(Debugger, "error: no such subterm")
> @@ -397,21 +396,19 @@
>  			Params ^ width, Params ^ lines, Str) },
>  	write_string_debugger(Debugger, Str).
>  
> -:- pred portray_raw_pretty(debugger, univ, format_params, io__state, io__state).
> -:- mode portray_raw_pretty(in, in, in, di, uo) is det.
> +:- pred portray_pretty(debugger, univ, format_params, io__state, io__state).
> +:- mode portray_pretty(in, in, in, di, uo) is det.
>  
> -portray_raw_pretty(Debugger, Univ, Params) -->
> -	{ term_to_string_raw_pretty(Univ, Params ^ width, 
> -			Params ^ depth, Str) },
> +portray_pretty(Debugger, Univ, Params) -->
> +	{ term_to_string_pretty(Univ, Params ^ width, Params ^ depth, Str) },
>  	write_string_debugger(Debugger, Str).
>  
>  
> -:- pred portray_pretty(debugger, univ, format_params, io__state, io__state).
> -:- mode portray_pretty(in, in, in, di, uo) is det.
> +:- pred portray_newpretty(debugger, univ, format_params, io__state, io__state).
> +:- mode portray_newpretty(in, in, in, di, uo) is det.
>  
> -portray_pretty(Debugger, Univ, Params) -->
> -	{ sized_pretty__univ_to_string_line(Univ, Params ^ width, 
> -			Params ^ lines, Str) },
> +portray_newpretty(Debugger, Univ, Params) -->
> +	{ term_to_string_newpretty(Univ, Params ^ lines, Params ^ width, Str) },
>  	write_string_debugger(Debugger, Str).
>  
>  	% The maximum estimated size for which we use `io__write'.
> @@ -522,16 +519,31 @@
>  % provides no way of doing this.
>  %
>  
> -:- pred term_to_string_raw_pretty(univ, int, int, string).
> -:- mode term_to_string_raw_pretty(in, in, in, out) is det.
> +:- pred term_to_string_pretty(univ, int, int, string).
> +:- mode term_to_string_pretty(in, in, in, out) is det.
>  
> -term_to_string_raw_pretty(Univ, Width, MaxDepth, Str) :-
> +term_to_string_pretty(Univ, Width, MaxDepth, Str) :-
>  	Value = univ_value(Univ),
>  	Doc = to_doc(MaxDepth, Value),
>  	Str = to_string(Width, Doc).
>  
>  %---------------------------------------------------------------------------%
>  %
> +% Print using the sizepretty.m module.
> +%
> +
> +:- pred term_to_string_newpretty(univ, int, int, string).
> +:- mode term_to_string_newpretty(in, in, in, out) is det.
> +
> +term_to_string_newpretty(Univ, Lines, Width, Str) :-
> +	sizepretty__annotate_with_size(Univ, measure_params(Width),
> +		size_count(Lines, 0), AnnotTerm),
> +	Doc = sizepretty__my_to_doc(AnnotTerm),
> +		% The plus 3 is to account for ", \n"
> +	Str = pprint__to_string((Width+3), Doc).
> +
> +%---------------------------------------------------------------------------%
> +%
>  % Verbose printing. Tree layout with numbered branches.
>  % Numbering makes it easier to change to subterms.
>  %
> @@ -879,14 +891,14 @@
>  		{ X = flat },
>  		send_term_to_socket(browser_str("flat"))
>  	;
> -		{ X = raw_pretty },
> -		send_term_to_socket(browser_str("raw_pretty"))
> +		{ X = pretty },
> +		send_term_to_socket(browser_str("pretty"))
>  	;
>  		{ X = verbose },
>  		send_term_to_socket(browser_str("verbose"))
>  	;
> -		{ X = pretty },
> -		send_term_to_socket(browser_str("pretty"))
> +		{ X = newpretty },
> +		send_term_to_socket(browser_str("newpretty"))
>  	).
>  
>  :- pred send_term_to_socket(term_browser_response, io__state, io__state).
> --- /home/stude/s/sthur/Review/mercury/browser/browser_info.m	Tue Jan 16 12:06:57 2001
> +++ /home/stude/s/sthur/ws1/mercury/browser/browser_info.m	Tue Jan 23 15:55:52 2001
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 2001 The University of Melbourne.
> +% Copyright (C) 2000 The University of Melbourne.

You shouldn't remove the Copyright 2000.  It should read:

	% Copyright (C) 2000-2001 The University of Melbourne.

>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -52,13 +52,12 @@
>  
>  	% The various ways of representing terms by the browser.
>  	%
> +	% Added the Format newpretty
>  :- type portray_format
>  	--->	flat
> -	;	raw_pretty	% calls pprint module directly, without first 
> -				% attempting to manipulate the term in any way
> +	;	pretty
>  	;	verbose
> -	;	pretty.		% allows user to specify the no of lines in

If you must abbreviate this, then "no." would be better.  In any case,
the user specifies the _maximum_ number of lines.

Also, you should generally write comments as complete sentences.

> -				% which the term has to be printed
> +	;	newpretty.
>  
>  :- type format_params
>  	--->	format_params(
> @@ -215,9 +214,9 @@
>  	--->	caller_params(
>  			default_format		:: portray_format,
>  			flat_params		:: format_params,
> -			raw_pretty_params	:: format_params,
> +			pretty_params		:: format_params,
>  			verbose_params		:: format_params,
> -			pretty_params		:: format_params
> +			newpretty_params	:: format_params
>  		).
>  
>  	% Initialise the persistent settings with default values.  The
> @@ -250,36 +249,39 @@
>  caller_type_print_defaults(Params) :-
>  	DefaultFormat = flat,
>  	Flat	  = format_params(3, 10, 80, 25),
> -	RawPretty = format_params(3, 10, 80, 25),
> +	Pretty	  = format_params(3, 10, 80, 25),
>  	Verbose	  = format_params(3, 10, 80, 25),
> -	Pretty    = format_params(3, 10, 80, 25),
> -	Params = caller_params(DefaultFormat, Flat, RawPretty, Verbose, Pretty).
> +	Newpretty = format_params(3, 10, 80, 25),
> +	Params = caller_params(DefaultFormat, Flat, Pretty, Verbose, Newpretty).
>  
>  :- pred caller_type_browse_defaults(caller_params).
>  :- mode caller_type_browse_defaults(out) is det.
>  
>  caller_type_browse_defaults(Params) :-
>  	DefaultFormat = verbose,
> -	Flat	  = format_params(10, 30, 80, 25),
> -	RawPretty = format_params(10, 30, 80, 25),
> -	Verbose	  = format_params(10, 30, 80, 25),
> -	Pretty    = format_params(10, 30, 80, 25),
> -	Params = caller_params(DefaultFormat, Flat, RawPretty, Verbose, Pretty).
> +	Flat	= format_params(10, 30, 80, 25),
> +	Pretty	= format_params(10, 30, 80, 25),
> +	Verbose	= format_params(10, 30, 80, 25),
> +	Newpretty = format_params(3, 10, 80, 25),
> +	Params = caller_params(DefaultFormat, Flat, Pretty, Verbose, Newpretty).
>  
>  :- pred caller_type_print_all_defaults(caller_params).
>  :- mode caller_type_print_all_defaults(out) is det.
>  
>  caller_type_print_all_defaults(Params) :-
>  	DefaultFormat = flat,
> -	Flat	  = format_params(3, 10, 80, 2),
> -	RawPretty = format_params(3, 10, 80, 2),
> -	Verbose   = format_params(3, 10, 80, 5),
> -	Pretty = format_params(3, 10, 80, 2),
> -	Params = caller_params(DefaultFormat, Flat, RawPretty, Verbose, Pretty).
> +	Flat	= format_params(3, 10, 80, 2),
> +	Pretty	= format_params(3, 10, 80, 2),
> +	Verbose	= format_params(3, 10, 80, 5),
> +	Newpretty = format_params(3, 10, 80, 2),
> +	Params = caller_params(DefaultFormat, Flat, Pretty, Verbose, Newpretty).
>  
> -browser_info__set_param(P0, B0, A0, F0, Pr0, V0, NPr0, Setting, State0, State):-
> +browser_info__set_param(P0, B0, A0, F0, Pr0, V0, _, Setting, State0, State):-
>  	default_all_yes(P0, B0, A0, P, B, A),
> -	default_all_yes(F0, Pr0, V0, NPr0, F, Pr, V, NPr),
> +	default_all_yes(F0, Pr0, V0, F, Pr, V),
> +	% XXX for now NPr = Pr but when "pretty format" is replaced with
> +	% "newpretty format" this statement is not required.
> +	NPr = Pr,
>  	maybe_set_param(P, F, Pr, V, NPr, Setting, State0 ^ print_params, 
>  			PParams),
>  	maybe_set_param(B, F, Pr, V, NPr, Setting, State0 ^ browse_params, 
> @@ -310,31 +312,6 @@
>  		C = C0
>  	).
>  
> -:- pred default_all_yes(bool, bool, bool, bool, bool, bool, bool, bool).
> -:- mode default_all_yes(in, in, in, in, out, out, out, out) is det.
> -
> -default_all_yes(A0, B0, C0, D0, A, B, C, D) :-
> -	%
> -	% If none of the flags are set, the command by default
> -	% applies to _all_ caller types/formats.
> -	%
> -	(
> -		A0 = no,
> -		B0 = no,
> -		C0 = no,
> -		D0 = no
> -	->
> -		A = yes,
> -		B = yes,
> -		C = yes,
> -		D = yes
> -	;
> -		A = A0,
> -		B = B0,
> -		C = C0,
> -		D = D0
> -	).
> -
>  :- pred maybe_set_param(bool, bool, bool, bool, bool, setting, caller_params,
>  		caller_params).
>  :- mode maybe_set_param(in, in, in, in, in, in, in, out) is det.
> @@ -347,11 +324,11 @@
>  		Params = Params0 ^ default_format := NewFormat
>  	;
>  		maybe_set_param_2(F, Setting, Params0 ^ flat_params, FParams),
> -		maybe_set_param_2(Pr, Setting, Params0 ^ raw_pretty_params,
> +		maybe_set_param_2(Pr, Setting, Params0 ^ pretty_params,
>  				PrParams),
>  		maybe_set_param_2(V, Setting, Params0 ^ verbose_params,
>  				VParams),
> -		maybe_set_param_2(NPr, Setting, Params0 ^ pretty_params,
> +		maybe_set_param_2(NPr, Setting, Params0 ^ newpretty_params,
>  				NPrParams),
>  		Params = caller_params(Params0 ^ default_format, FParams,
>  				PrParams, VParams, NPrParams)
> @@ -380,9 +357,9 @@
>  :- mode get_caller_format_params(in, in, out) is det.
>  
>  get_caller_format_params(Params, flat, Params ^ flat_params).
> -get_caller_format_params(Params, raw_pretty, Params ^ raw_pretty_params).
> -get_caller_format_params(Params, verbose, Params ^ verbose_params).
>  get_caller_format_params(Params, pretty, Params ^ pretty_params).
> +get_caller_format_params(Params, verbose, Params ^ verbose_params).
> +get_caller_format_params(Params, newpretty, Params ^ newpretty_params).
>  
>  %---------------------------------------------------------------------------%
>  
> --- /home/stude/s/sthur/Review/mercury/browser/parse.m	Wed Jan 17 10:45:06 2001
> +++ /home/stude/s/sthur/ws1/mercury/browser/parse.m	Tue Jan 23 15:56:03 2001
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 1998-2001 The University of Melbourne.
> +% Copyright (C) 1998-2000 The University of Melbourne.
>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -45,9 +45,8 @@
>  %
>  %	fmt:
>  %		"flat"
> -%		"raw_pretty"
> -%		"verbose"
>  %		"pretty"
> +%		"verbose"
>  %
>  %	path:
>  %		["/"] [dirs]
> @@ -167,7 +166,7 @@
>  	; char__is_digit(C) ->
>  		dig_to_int(C, N),
>  		lexer_num(N, Cs, Toks)
> -	; char__is_alpha_or_underscore(C) ->
> +	; char__is_alpha(C) ->
>  		lexer_name(C, Cs, Toks)
>  	; char__is_whitespace(C) ->
>  		lexer(Cs, Toks)
> @@ -218,7 +217,7 @@
>  :- pred lexer_name(char, list(char), list(token)).
>  :- mode lexer_name(in, in, out) is det.
>  lexer_name(C, Cs, Toks) :-
> -	list__takewhile(char__is_alpha_or_underscore, Cs, Letters, Rest),
> +	list__takewhile(char__is_alpha, Cs, Letters, Rest),
>  	string__from_char_list([C | Letters], Name),
>  	lexer(Rest, Toks2),
>  	Toks = [name(Name) | Toks2].
> @@ -332,13 +331,13 @@
>  		Toks = [Fmt],
>  		( Fmt = name("flat") ->
>  			Setting = format(flat)
> -		; Fmt = name("raw_pretty") ->
> -			Setting = format(raw_pretty)
> +		; Fmt = name("pretty") ->
> +			Setting = format(pretty)
>  		; Fmt = name("verbose") ->
>  			Setting = format(verbose)
>  		; 
> -			Fmt = name("pretty"),
> -			Setting = format(pretty)
> +			Fmt = name("newpretty"),
> +			Setting = format(newpretty)
>  		)
>  	;
>  		fail
> @@ -429,11 +428,11 @@
>  :- mode show_format(in, di, uo) is det.
>  show_format(flat) -->
>  	io__write_string("flat").
> -show_format(raw_pretty) -->
> -	io__write_string("raw_pretty").
> -show_format(verbose) -->
> -	io__write_string("verbose").
>  show_format(pretty) -->
>  	io__write_string("pretty").
> +show_format(verbose) -->
> +	io__write_string("verbose").
> +show_format(newpretty) -->
> +	io__write_string("newpretty").
>  
>  %---------------------------------------------------------------------------%
> --- /home/stude/s/sthur/Review/mercury/trace/mercury_trace_browse.c	Tue Jan 16 12:13:15 2001
> +++ /home/stude/s/sthur/ws1/mercury/trace/mercury_trace_browse.c	Tue Jan 23 16:15:35 2001
> @@ -1,5 +1,5 @@
>  /*
> -** Copyright (C) 1998-2001 The University of Melbourne.
> +** Copyright (C) 1998-2000 The University of Melbourne.
>  ** This file may only be copied under the terms of the GNU Library General
>  ** Public License - see the file COPYING.LIB in the Mercury distribution.
>  */
> @@ -142,8 +142,8 @@
>  
>  bool
>  MR_trace_set_browser_param(MR_Bool print, MR_Bool browse, MR_Bool print_all,
> -		MR_Bool flat, MR_Bool raw_pretty, MR_Bool verbose, 
> -		MR_Bool pretty, const char *param, const char *value)
> +		MR_Bool flat, MR_Bool pretty, MR_Bool verbose, 
> +		MR_Bool newpretty, const char *param, const char *value)
>  {
>  	int			depth, size, width, lines;
>  	MR_Browse_Format	new_format;
> @@ -163,7 +163,7 @@
>  	{
>  		MR_TRACE_CALL_MERCURY(
>  			ML_BROWSE_set_param_depth(print, browse, print_all,
> -				flat, raw_pretty, verbose, pretty, depth,
> +				flat, pretty, verbose, newpretty, depth,
>  				MR_trace_browser_persistent_state,
>  				&MR_trace_browser_persistent_state);
>  		);
> @@ -172,7 +172,7 @@
>  	{
>  		MR_TRACE_CALL_MERCURY(
>  			ML_BROWSE_set_param_size(print, browse, print_all,
> -				flat, raw_pretty, verbose, pretty, size,
> +				flat, pretty, verbose, newpretty, size,
>  				MR_trace_browser_persistent_state,
>  				&MR_trace_browser_persistent_state);
>  		);
> @@ -181,7 +181,7 @@
>  	{
>  		MR_TRACE_CALL_MERCURY(
>  			ML_BROWSE_set_param_width(print, browse, print_all,
> -				flat, raw_pretty, verbose, pretty, width,
> +				flat, pretty, verbose, newpretty, width,
>  				MR_trace_browser_persistent_state,
>  				&MR_trace_browser_persistent_state);
>  		);
> @@ -190,7 +190,7 @@
>  	{
>  		MR_TRACE_CALL_MERCURY(
>  			ML_BROWSE_set_param_lines(print, browse, print_all,
> -				flat, raw_pretty, verbose, pretty, lines,
> +				flat, pretty, verbose, newpretty, lines,
>  				MR_trace_browser_persistent_state,
>  				&MR_trace_browser_persistent_state);
>  		);
> @@ -214,14 +214,14 @@
>  	if (streq(str, "flat")) {
>  		*format = MR_BROWSE_FORMAT_FLAT;
>  		return TRUE;
> -	} else if (streq(str, "raw_pretty")) {
> -		*format = MR_BROWSE_FORMAT_RAW_PRETTY;
> +	} else if (streq(str, "pretty")) {
> +		*format = MR_BROWSE_FORMAT_PRETTY;
>  		return TRUE;
>  	} else if (streq(str, "verbose")) {
>  		*format = MR_BROWSE_FORMAT_VERBOSE;
>  		return TRUE;
> -	} else if (streq(str, "pretty")) {
> -		*format = MR_BROWSE_FORMAT_PRETTY;
> +	} else if (streq(str, "newpretty")) {
> +		*format = MR_BROWSE_FORMAT_NEWPRETTY;
>  		return TRUE;
>  	}
>  	return FALSE;
> --- /home/stude/s/sthur/Review/mercury/trace/mercury_trace_browse.h	Tue Jan 16 12:29:45 2001
> +++ /home/stude/s/sthur/ws1/mercury/trace/mercury_trace_browse.h	Tue Jan 23 16:00:09 2001
> @@ -1,5 +1,5 @@
>  /*
> -** Copyright (C) 1998-2001 The University of Melbourne.
> +** Copyright (C) 1998-2000 The University of Melbourne.
>  ** This file may only be copied under the terms of the GNU Library General
>  ** Public License - see the file COPYING.LIB in the Mercury distribution.
>  */
> @@ -29,9 +29,9 @@
>  
>  typedef enum {
>  	MR_BROWSE_FORMAT_FLAT,
> -	MR_BROWSE_FORMAT_RAW_PRETTY,
> +	MR_BROWSE_FORMAT_PRETTY,
>  	MR_BROWSE_FORMAT_VERBOSE,
> -	MR_BROWSE_FORMAT_PRETTY
> +	MR_BROWSE_FORMAT_NEWPRETTY
>  } MR_Browse_Format;
>  
>  /*
> @@ -59,8 +59,8 @@
>  ** Set browser parameters.
>  */
>  extern	bool	MR_trace_set_browser_param(MR_Bool print, MR_Bool browse,
> -			MR_Bool print_all, MR_Bool flat, MR_Bool raw_pretty,
> -			MR_Bool verbose, MR_Bool pretty, const char *param, 
> +			MR_Bool print_all, MR_Bool flat, MR_Bool pretty,
> +			MR_Bool verbose, MR_Bool newpretty, const char *param, 
>  			const char *value);
>  
>  /*
> --- /home/stude/s/sthur/Review/mercury/trace/mercury_trace_internal.c	Tue Jan 23 12:11:32 2001
> +++ /home/stude/s/sthur/ws1/mercury/trace/mercury_trace_internal.c	Tue Jan 23 16:00:15 2001
> @@ -178,8 +178,8 @@
>  			const char *item);
>  static	bool	MR_trace_options_param_set(MR_Bool *print_set,
>  			MR_Bool *browse_set, MR_Bool *print_all_set,
> -			MR_Bool *flat_format, MR_Bool *raw_pretty_format,
> -			MR_Bool *verbose_format, MR_Bool *pretty_format, 
> +			MR_Bool *flat_format, MR_Bool *pretty_format,
> +			MR_Bool *verbose_format, MR_Bool *newpretty_format, 
>  			char ***words, int *word_count, const char *cat, 
>  			const char *item);
>  static	void	MR_trace_usage(const char *cat, const char *item);
> @@ -1094,23 +1094,22 @@
>  		MR_Bool			browse_set;
>  		MR_Bool			print_all_set;
>  		MR_Bool			flat_format;
> -		MR_Bool			raw_pretty_format;
> -		MR_Bool			verbose_format;
>  		MR_Bool			pretty_format;
> +		MR_Bool			verbose_format;
> +		MR_Bool			newpretty_format;
>  
>  		if (! MR_trace_options_param_set(&print_set, &browse_set,
> -				&print_all_set, &flat_format, 
> -				&raw_pretty_format, &verbose_format, 
> -				&pretty_format, &words, &word_count, "browsing",
> -				"set"))
> +				&print_all_set, &flat_format, &pretty_format,
> +				&verbose_format, &newpretty_format, &words, 
> +				&word_count, "browsing", "set"))
>  		{
>  			; /* the usage message has already been printed */
>  		}
>  		else if (word_count != 3 ||
>  				! MR_trace_set_browser_param(print_set,
>  					browse_set, print_all_set, flat_format,
> -					raw_pretty_format, verbose_format, 
> -					pretty_format, words[1], words[2]))
> +					pretty_format, verbose_format, 
> +					newpretty_format, words[1], words[2]))
>  		{
>  			MR_trace_usage("browsing", "set");
>  		}
> @@ -2410,9 +2409,9 @@
>  static struct MR_option MR_trace_format_opts[] = 
>  {
>  	{ "flat",	FALSE,	NULL,	'f' },
> -	{ "raw_pretty",	FALSE,	NULL,	'r' },
> -	{ "verbose",	FALSE,	NULL,	'v' },
>  	{ "pretty",	FALSE,	NULL,	'p' },
> +	{ "verbose",	FALSE,	NULL,	'v' },
> +	{ "newpretty",	FALSE,	NULL,	'x' },
>  	{ NULL,		FALSE,	NULL,	0 }
>  };
>  
> @@ -2424,7 +2423,7 @@
>  
>  	*format = MR_BROWSE_DEFAULT_FORMAT;
>  	MR_optind = 0;
> -	while ((c = MR_getopt_long(*word_count, *words, "frvp",
> +	while ((c = MR_getopt_long(*word_count, *words, "fpvx",
>  			MR_trace_format_opts, NULL)) != EOF)
>  	{
>  		switch (c) {
> @@ -2433,16 +2432,16 @@
>  				*format = MR_BROWSE_FORMAT_FLAT;
>  				break;
>  
> -			case 'r':
> -				*format = MR_BROWSE_FORMAT_RAW_PRETTY;
> +			case 'p':
> +				*format = MR_BROWSE_FORMAT_PRETTY;
>  				break;
>  
>  			case 'v':
>  				*format = MR_BROWSE_FORMAT_VERBOSE;
>  				break;
>  
> -			case 'p':
> -				*format = MR_BROWSE_FORMAT_PRETTY;
> +			case 'x':
> +				*format = MR_BROWSE_FORMAT_NEWPRETTY;
>  				break;
>  
>  			default:
> @@ -2459,9 +2458,9 @@
>  static struct MR_option MR_trace_param_set_opts[] = 
>  {
>  	{ "flat",	FALSE,	NULL,	'f' },
> -	{ "raw_pretty",	FALSE,	NULL,	'r' },
> +	{ "pretty",	FALSE,	NULL,	'p' },
>  	{ "verbose",	FALSE,	NULL,	'v' },
> -	{ "pretty",	FALSE,	NULL,	'p' },	
> +	{ "newpretty",	FALSE,	NULL,	'x' },	
>  	{ "print",	FALSE,	NULL,	'P' },
>  	{ "browse",	FALSE,	NULL,	'B' },
>  	{ "print-all",	FALSE,	NULL,	'A' },
> @@ -2470,10 +2469,9 @@
>  
>  static bool
>  MR_trace_options_param_set(MR_Bool *print_set, MR_Bool *browse_set,
> -	MR_Bool *print_all_set, MR_Bool *flat_format, 
> -	MR_Bool *raw_pretty_format, MR_Bool *verbose_format, 
> -	MR_Bool *pretty_format, char ***words, int *word_count, const char *cat,
> -	const char *item)
> +	MR_Bool *print_all_set, MR_Bool *flat_format, MR_Bool *pretty_format,
> +	MR_Bool *verbose_format, MR_Bool *newpretty_format, char ***words, 
> +	int *word_count, const char *cat, const char *item)
>  {
>  	int	c;
>  
> @@ -2481,12 +2479,12 @@
>  	*browse_set = FALSE;
>  	*print_all_set = FALSE;
>  	*flat_format = FALSE;
> -	*raw_pretty_format = FALSE;
> -	*verbose_format = FALSE;
>  	*pretty_format = FALSE;
> +	*verbose_format = FALSE;
> +	*newpretty_format = FALSE;
>  
>  	MR_optind = 0;
> -	while ((c = MR_getopt_long(*word_count, *words, "PBAfrvp",
> +	while ((c = MR_getopt_long(*word_count, *words, "PBAfpvx",
>  			MR_trace_param_set_opts, NULL)) != EOF)
>  	{
>  		switch (c) {
> @@ -2495,16 +2493,16 @@
>  				*flat_format = TRUE;
>  				break;
>  
> -			case 'r':
> -				*raw_pretty_format = TRUE;
> +			case 'p':
> +				*pretty_format = TRUE;
>  				break;
>  
>  			case 'v':
>  				*verbose_format = TRUE;
>  				break;
>  
> -			case 'p':
> -				*pretty_format = TRUE;
> +			case 'x':
> +				*newpretty_format = TRUE;
>  				break;
>  
>  			case 'P':
> 
> ################################################################################
> # 			The Following is the New Diff 			       #
> ################################################################################
> 
> ? make_all.log
> ? make_install.log
> ? browser/browse.dv
> ? compiler/maybe_mlds_to_gcc.m
> ? scripts/canonical_grade
> Index: browser/browse.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/browser/browse.m,v
> retrieving revision 1.17
> diff -u -r1.17 browse.m
> --- browser/browse.m	2001/01/09 23:30:13	1.17
> +++ browser/browse.m	2001/01/23 05:33:22
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 1998-2000 The University of Melbourne.
> +% Copyright (C) 1998-2001 The University of Melbourne.
>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -82,7 +82,7 @@
>  %---------------------------------------------------------------------------%
>  :- implementation.
>  
> -:- import_module mdb__parse, mdb__util, mdb__frame.
> +:- import_module mdb__parse, mdb__util, mdb__frame, mdb__sized_pretty.
>  :- import_module string, list, parser, require, std_util, int, char, pprint.
>  :- import_module bool.
>  
> @@ -294,8 +294,8 @@
>  	% XXX We can't yet give options to the `set' command.
>  	%
>  	No = bool__no,
> -	browser_info__set_param(No, No, No, No, No, No, Setting, Info0 ^ state,
> -			NewState),
> +	browser_info__set_param(No, No, No, No, No, No, No, Setting, 
> +			Info0 ^ state, NewState),
>  	Info = Info0 ^ state := NewState.
>  
>  :- pred help(debugger::in, io__state::di, io__state::uo) is det.
> @@ -317,7 +317,8 @@
>  "\th              -- help\n",
>  "\n",
>  "-- settings:\n",
> -"--    size; depth; path; format (flat pretty verbose); width; lines\n",
> +"--    size; depth; path; format (flat raw_pretty verbose pretty); width; ",
> +"lines\n",
>  "--    Paths can be Unix-style or SICStus-style: /2/3/1 or ^2^3^1\n",
>  "\n"],
>  		HelpMessage) },
> @@ -342,11 +343,14 @@
>  			{ Format = flat },
>  			portray_flat(Debugger, SubUniv, Params)
>  		;
> -			{ Format = pretty },
> -			portray_pretty(Debugger, SubUniv, Params)
> +			{ Format = raw_pretty },
> +			portray_raw_pretty(Debugger, SubUniv, Params)
>  		;
>  			{ Format = verbose },
>  			portray_verbose(Debugger, SubUniv, Params)
> +		;
> +			{ Format = pretty },
> +			portray_pretty(Debugger, SubUniv, Params)
>  		)
>  	;
>  		write_string_debugger(Debugger, "error: no such subterm")
> @@ -393,14 +397,23 @@
>  			Params ^ width, Params ^ lines, Str) },
>  	write_string_debugger(Debugger, Str).
>  
> +:- pred portray_raw_pretty(debugger, univ, format_params, io__state, io__state).
> +:- mode portray_raw_pretty(in, in, in, di, uo) is det.
> +
> +portray_raw_pretty(Debugger, Univ, Params) -->
> +	{ term_to_string_raw_pretty(Univ, Params ^ width, 
> +			Params ^ depth, Str) },
> +	write_string_debugger(Debugger, Str).
> +
> +
>  :- pred portray_pretty(debugger, univ, format_params, io__state, io__state).
>  :- mode portray_pretty(in, in, in, di, uo) is det.
>  
>  portray_pretty(Debugger, Univ, Params) -->
> -	{ term_to_string_pretty(Univ, Params ^ width, Params ^ depth, Str) },
> +	{ sized_pretty__univ_to_string_line(Univ, Params ^ width, 
> +			Params ^ lines, Str) },
>  	write_string_debugger(Debugger, Str).
>  
> -
>  	% The maximum estimated size for which we use `io__write'.
>  :- pred max_print_size(int::out) is det.
>  max_print_size(60).
> @@ -509,10 +522,10 @@
>  % provides no way of doing this.
>  %
>  
> -:- pred term_to_string_pretty(univ, int, int, string).
> -:- mode term_to_string_pretty(in, in, in, out) is det.
> +:- pred term_to_string_raw_pretty(univ, int, int, string).
> +:- mode term_to_string_raw_pretty(in, in, in, out) is det.
>  
> -term_to_string_pretty(Univ, Width, MaxDepth, Str) :-
> +term_to_string_raw_pretty(Univ, Width, MaxDepth, Str) :-
>  	Value = univ_value(Univ),
>  	Doc = to_doc(MaxDepth, Value),
>  	Str = to_string(Width, Doc).
> @@ -866,11 +879,14 @@
>  		{ X = flat },
>  		send_term_to_socket(browser_str("flat"))
>  	;
> -		{ X = pretty },
> -		send_term_to_socket(browser_str("pretty"))
> +		{ X = raw_pretty },
> +		send_term_to_socket(browser_str("raw_pretty"))
>  	;
>  		{ X = verbose },
>  		send_term_to_socket(browser_str("verbose"))
> +	;
> +		{ X = pretty },
> +		send_term_to_socket(browser_str("pretty"))
>  	).
>  
>  :- pred send_term_to_socket(term_browser_response, io__state, io__state).
> Index: browser/browser_info.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/browser/browser_info.m,v
> retrieving revision 1.1
> diff -u -r1.1 browser_info.m
> --- browser/browser_info.m	2000/10/27 08:38:49	1.1
> +++ browser/browser_info.m	2001/01/23 05:33:22
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 2000 The University of Melbourne.
> +% Copyright (C) 2001 The University of Melbourne.
>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -54,8 +54,11 @@
>  	%
>  :- type portray_format
>  	--->	flat
> -	;	pretty
> -	;	verbose.
> +	;	raw_pretty	% calls pprint module directly, without first 
> +				% attempting to manipulate the term in any way
> +	;	verbose
> +	;	pretty.		% allows user to specify the no of lines in
> +				% which the term has to be printed
>  
>  :- type format_params
>  	--->	format_params(
> @@ -110,8 +113,9 @@
>  	% and -v, in that order.
>  	%
>  :- pred browser_info__set_param(bool::in, bool::in, bool::in, bool::in,
> -		bool::in, bool::in, setting::in, browser_persistent_state::in,
> -		browser_persistent_state::out) is det.
> +		bool::in, bool::in, bool::in, setting::in, 
> +		browser_persistent_state::in, browser_persistent_state::out) 
> +		is det.
>  
>  %---------------------------------------------------------------------------%
>  
> @@ -127,40 +131,40 @@
>  	%
>  
>  :- pred set_param_depth(bool::in, bool::in, bool::in, bool::in, bool::in,
> -		bool::in, int::in, browser_persistent_state::in,
> +		bool::in, bool::in, int::in, browser_persistent_state::in,
>  		browser_persistent_state::out) is det.
> -:- pragma export(set_param_depth(in, in, in, in, in, in, in, in, out),
> +:- pragma export(set_param_depth(in, in, in, in, in, in, in, in, in, out),
>  		"ML_BROWSE_set_param_depth").
>  
> -set_param_depth(P, B, A, F, Pr, V, Depth) -->
> -	browser_info__set_param(P, B, A, F, Pr, V, depth(Depth)).
> +set_param_depth(P, B, A, F, Pr, V, NPr, Depth) -->
> +	browser_info__set_param(P, B, A, F, Pr, V, NPr,  depth(Depth)).
>  
>  :- pred set_param_size(bool::in, bool::in, bool::in, bool::in, bool::in,
> -		bool::in, int::in, browser_persistent_state::in,
> +		bool::in, bool::in, int::in, browser_persistent_state::in,
>  		browser_persistent_state::out) is det.
> -:- pragma export(set_param_size(in, in, in, in, in, in, in, in, out),
> +:- pragma export(set_param_size(in, in, in, in, in, in, in, in, in, out),
>  		"ML_BROWSE_set_param_size").
>  
> -set_param_size(P, B, A, F, Pr, V, Size) -->
> -	browser_info__set_param(P, B, A, F, Pr, V, size(Size)).
> +set_param_size(P, B, A, F, Pr, NPr, V, Size) -->
> +	browser_info__set_param(P, B, A, F, Pr, V, NPr, size(Size)).
>  
>  :- pred set_param_width(bool::in, bool::in, bool::in, bool::in, bool::in,
> -		bool::in, int::in, browser_persistent_state::in,
> +		bool::in, bool::in, int::in, browser_persistent_state::in,
>  		browser_persistent_state::out) is det.
> -:- pragma export(set_param_width(in, in, in, in, in, in, in, in, out),
> +:- pragma export(set_param_width(in, in, in, in, in, in, in, in, in, out),
>  		"ML_BROWSE_set_param_width").
>  
> -set_param_width(P, B, A, F, Pr, V, Width) -->
> -	browser_info__set_param(P, B, A, F, Pr, V, width(Width)).
> +set_param_width(P, B, A, F, Pr, V, NPr, Width) -->
> +	browser_info__set_param(P, B, A, F, Pr, V, NPr, width(Width)).
>  
>  :- pred set_param_lines(bool::in, bool::in, bool::in, bool::in, bool::in,
> -		bool::in, int::in, browser_persistent_state::in,
> +		bool::in, bool::in, int::in, browser_persistent_state::in,
>  		browser_persistent_state::out) is det.
> -:- pragma export(set_param_lines(in, in, in, in, in, in, in, in, out),
> +:- pragma export(set_param_lines(in, in, in, in, in, in, in, in, in, out),
>  		"ML_BROWSE_set_param_lines").
>  
> -set_param_lines(P, B, A, F, Pr, V, Lines) -->
> -	browser_info__set_param(P, B, A, F, Pr, V, lines(Lines)).
> +set_param_lines(P, B, A, F, Pr, V, NPr, Lines) -->
> +	browser_info__set_param(P, B, A, F, Pr, V, NPr, lines(Lines)).
>  
>  :- pred set_param_format(bool::in, bool::in, bool::in, portray_format::in,
>  		browser_persistent_state::in, browser_persistent_state::out)
> @@ -172,7 +176,7 @@
>  	%
>  	% Any format flags are ignored for this parameter.
>  	%
> -	browser_info__set_param(P, B, A, no, no, no, format(Format)).
> +	browser_info__set_param(P, B, A, no, no, no, no, format(Format)).
>  
>  %---------------------------------------------------------------------------%
>  
> @@ -211,8 +215,9 @@
>  	--->	caller_params(
>  			default_format		:: portray_format,
>  			flat_params		:: format_params,
> -			pretty_params		:: format_params,
> -			verbose_params		:: format_params
> +			raw_pretty_params	:: format_params,
> +			verbose_params		:: format_params,
> +			pretty_params		:: format_params
>  		).
>  
>  	% Initialise the persistent settings with default values.  The
> @@ -244,37 +249,42 @@
>  
>  caller_type_print_defaults(Params) :-
>  	DefaultFormat = flat,
> -	Flat	= format_params(3, 10, 80, 25),
> -	Pretty	= format_params(3, 10, 80, 25),
> -	Verbose	= format_params(3, 10, 80, 25),
> -	Params	= caller_params(DefaultFormat, Flat, Pretty, Verbose).
> +	Flat	  = format_params(3, 10, 80, 25),
> +	RawPretty = format_params(3, 10, 80, 25),
> +	Verbose	  = format_params(3, 10, 80, 25),
> +	Pretty    = format_params(3, 10, 80, 25),
> +	Params = caller_params(DefaultFormat, Flat, RawPretty, Verbose, Pretty).
>  
>  :- pred caller_type_browse_defaults(caller_params).
>  :- mode caller_type_browse_defaults(out) is det.
>  
>  caller_type_browse_defaults(Params) :-
>  	DefaultFormat = verbose,
> -	Flat	= format_params(10, 30, 80, 25),
> -	Pretty	= format_params(10, 30, 80, 25),
> -	Verbose	= format_params(10, 30, 80, 25),
> -	Params	= caller_params(DefaultFormat, Flat, Pretty, Verbose).
> +	Flat	  = format_params(10, 30, 80, 25),
> +	RawPretty = format_params(10, 30, 80, 25),
> +	Verbose	  = format_params(10, 30, 80, 25),
> +	Pretty    = format_params(10, 30, 80, 25),
> +	Params = caller_params(DefaultFormat, Flat, RawPretty, Verbose, Pretty).
>  
>  :- pred caller_type_print_all_defaults(caller_params).
>  :- mode caller_type_print_all_defaults(out) is det.
>  
>  caller_type_print_all_defaults(Params) :-
>  	DefaultFormat = flat,
> -	Flat	= format_params(3, 10, 80, 2),
> -	Pretty	= format_params(3, 10, 80, 2),
> -	Verbose	= format_params(3, 10, 80, 5),
> -	Params	= caller_params(DefaultFormat, Flat, Pretty, Verbose).
> +	Flat	  = format_params(3, 10, 80, 2),
> +	RawPretty = format_params(3, 10, 80, 2),
> +	Verbose   = format_params(3, 10, 80, 5),
> +	Pretty = format_params(3, 10, 80, 2),
> +	Params = caller_params(DefaultFormat, Flat, RawPretty, Verbose, Pretty).
>  
> -browser_info__set_param(P0, B0, A0, F0, Pr0, V0, Setting, State0, State) :-
> +browser_info__set_param(P0, B0, A0, F0, Pr0, V0, NPr0, Setting, State0, State):-
>  	default_all_yes(P0, B0, A0, P, B, A),
> -	default_all_yes(F0, Pr0, V0, F, Pr, V),
> -	maybe_set_param(P, F, Pr, V, Setting, State0 ^ print_params, PParams),
> -	maybe_set_param(B, F, Pr, V, Setting, State0 ^ browse_params, BParams),
> -	maybe_set_param(A, F, Pr, V, Setting, State0 ^ print_all_params,
> +	default_all_yes(F0, Pr0, V0, NPr0, F, Pr, V, NPr),
> +	maybe_set_param(P, F, Pr, V, NPr, Setting, State0 ^ print_params, 
> +			PParams),
> +	maybe_set_param(B, F, Pr, V, NPr, Setting, State0 ^ browse_params, 
> +			BParams),
> +	maybe_set_param(A, F, Pr, V, NPr, Setting, State0 ^ print_all_params,
>  			AParams),
>  	State = browser_persistent_state(PParams, BParams, AParams).
>  
> @@ -299,25 +309,52 @@
>  		B = B0,
>  		C = C0
>  	).
> +
> +:- pred default_all_yes(bool, bool, bool, bool, bool, bool, bool, bool).
> +:- mode default_all_yes(in, in, in, in, out, out, out, out) is det.
> +
> +default_all_yes(A0, B0, C0, D0, A, B, C, D) :-
> +	%
> +	% If none of the flags are set, the command by default
> +	% applies to _all_ caller types/formats.
> +	%
> +	(
> +		A0 = no,
> +		B0 = no,
> +		C0 = no,
> +		D0 = no
> +	->
> +		A = yes,
> +		B = yes,
> +		C = yes,
> +		D = yes
> +	;
> +		A = A0,
> +		B = B0,
> +		C = C0,
> +		D = D0
> +	).
>  
> -:- pred maybe_set_param(bool, bool, bool, bool, setting, caller_params,
> +:- pred maybe_set_param(bool, bool, bool, bool, bool, setting, caller_params,
>  		caller_params).
> -:- mode maybe_set_param(in, in, in, in, in, in, out) is det.
> +:- mode maybe_set_param(in, in, in, in, in, in, in, out) is det.
>  
> -maybe_set_param(no, _, _, _, _, Params, Params).
> -maybe_set_param(yes, F, Pr, V, Setting, Params0, Params) :-
> +maybe_set_param(no, _, _, _, _, _, Params, Params).
> +maybe_set_param(yes, F, Pr, V, NPr, Setting, Params0, Params) :-
>  	(
>  		Setting = format(NewFormat)
>  	->
>  		Params = Params0 ^ default_format := NewFormat
>  	;
>  		maybe_set_param_2(F, Setting, Params0 ^ flat_params, FParams),
> -		maybe_set_param_2(Pr, Setting, Params0 ^ pretty_params,
> +		maybe_set_param_2(Pr, Setting, Params0 ^ raw_pretty_params,
>  				PrParams),
>  		maybe_set_param_2(V, Setting, Params0 ^ verbose_params,
>  				VParams),
> +		maybe_set_param_2(NPr, Setting, Params0 ^ pretty_params,
> +				NPrParams),
>  		Params = caller_params(Params0 ^ default_format, FParams,
> -				PrParams, VParams)
> +				PrParams, VParams, NPrParams)
>  	).
>  
>  :- pred maybe_set_param_2(bool, setting, format_params, format_params).
> @@ -343,8 +380,9 @@
>  :- mode get_caller_format_params(in, in, out) is det.
>  
>  get_caller_format_params(Params, flat, Params ^ flat_params).
> -get_caller_format_params(Params, pretty, Params ^ pretty_params).
> +get_caller_format_params(Params, raw_pretty, Params ^ raw_pretty_params).
>  get_caller_format_params(Params, verbose, Params ^ verbose_params).
> +get_caller_format_params(Params, pretty, Params ^ pretty_params).
>  
>  %---------------------------------------------------------------------------%
>  
> Index: browser/mdb.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/browser/mdb.m,v
> retrieving revision 1.4
> diff -u -r1.4 mdb.m
> --- browser/mdb.m	2000/10/27 08:38:49	1.4
> +++ browser/mdb.m	2001/01/23 05:33:22
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 1998-2000 The University of Melbourne.
> +% Copyright (C) 1998-2001 The University of Melbourne.
>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -20,7 +20,7 @@
>  
>  :- implementation.
>  
> -:- include_module frame, parse, util.
> +:- include_module frame, parse, util, sized_pretty.
>  :- include_module declarative_analyser, declarative_oracle, declarative_user.
>  
>  	% XXX these modules are more generally useful, but the
> Index: browser/parse.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/browser/parse.m,v
> retrieving revision 1.9
> diff -u -r1.9 parse.m
> --- browser/parse.m	2000/10/27 08:38:50	1.9
> +++ browser/parse.m	2001/01/23 05:33:22
> @@ -1,5 +1,5 @@
>  %---------------------------------------------------------------------------%
> -% Copyright (C) 1998-2000 The University of Melbourne.
> +% Copyright (C) 1998-2001 The University of Melbourne.
>  % This file may only be copied under the terms of the GNU Library General
>  % Public License - see the file COPYING.LIB in the Mercury distribution.
>  %---------------------------------------------------------------------------%
> @@ -45,8 +45,9 @@
>  %
>  %	fmt:
>  %		"flat"
> -%		"pretty"
> +%		"raw_pretty"
>  %		"verbose"
> +%		"pretty"
>  %
>  %	path:
>  %		["/"] [dirs]
> @@ -166,7 +167,7 @@
>  	; char__is_digit(C) ->
>  		dig_to_int(C, N),
>  		lexer_num(N, Cs, Toks)
> -	; char__is_alpha(C) ->
> +	; char__is_alpha_or_underscore(C) ->
>  		lexer_name(C, Cs, Toks)
>  	; char__is_whitespace(C) ->
>  		lexer(Cs, Toks)
> @@ -217,7 +218,7 @@
>  :- pred lexer_name(char, list(char), list(token)).
>  :- mode lexer_name(in, in, out) is det.
>  lexer_name(C, Cs, Toks) :-
> -	list__takewhile(char__is_alpha, Cs, Letters, Rest),
> +	list__takewhile(char__is_alpha_or_underscore, Cs, Letters, Rest),
>  	string__from_char_list([C | Letters], Name),
>  	lexer(Rest, Toks2),
>  	Toks = [name(Name) | Toks2].
> @@ -331,11 +332,13 @@
>  		Toks = [Fmt],
>  		( Fmt = name("flat") ->
>  			Setting = format(flat)
> -		; Fmt = name("pretty") ->
> -			Setting = format(pretty)
> -		;
> -			Fmt = name("verbose"),
> +		; Fmt = name("raw_pretty") ->
> +			Setting = format(raw_pretty)
> +		; Fmt = name("verbose") ->
>  			Setting = format(verbose)
> +		; 
> +			Fmt = name("pretty"),
> +			Setting = format(pretty)
>  		)
>  	;
>  		fail
> @@ -426,9 +429,11 @@
>  :- mode show_format(in, di, uo) is det.
>  show_format(flat) -->
>  	io__write_string("flat").
> -show_format(pretty) -->
> -	io__write_string("pretty").
> +show_format(raw_pretty) -->
> +	io__write_string("raw_pretty").
>  show_format(verbose) -->
>  	io__write_string("verbose").
> +show_format(pretty) -->
> +	io__write_string("pretty").
>  
>  %---------------------------------------------------------------------------%
> Index: browser/sized_pretty.m
> ===================================================================
> RCS file: sized_pretty.m
> diff -N sized_pretty.m
> --- /dev/null	Wed Nov 15 09:24:47 2000
> +++ sized_pretty.m	Tue Jan 23 16:33:22 2001
> @@ -0,0 +1,903 @@
> +%---------------------------------------------------------------------------%
> +% Copyright (C) 1998-2001 The University of Melbourne.
> +% This file may only be copied under the terms of the GNU Library General
> +% Public License - see the file COPYING.LIB in the Mercury distribution.
> +%---------------------------------------------------------------------------%
> +
> +% sized_pretty-	When printing a term during debugging this module allows
> +%		the user to put a limit on the size of the term displayed.
> +%               This limit is specified by setting the number of lines you 
> +%               want and the width of these lines. 
> +%
> +%
> +% author: sthur
> +%
> +% How to use sized_pretty.m :
> +% ---------------------------
> +%
> +% Call univ_to_string_line with the follwing variables:
> +% 	univ_to_string_line(Univ, LineWidth, Lines, String)
> +%		where Univ 	: is the Term (in univ type) you want to convert
> +%		      LineWidth : is the length of the lines
> +%		      Lines 	: is the number of lines you want the term to be
> +%		            	  printed on
> +%		      String	: output string
> +%
> +% EXAMPLES
> +% --------
> +%
> +% Term Used in these examples:
> +%
> +%	Term = big(
> +%                 big(
> +%                    big(
> +%                       small,
> +%			"Level 3",
> +%                       small
> +%                       ),
> +%		     "Level 2",
> +%                    small
> +%                    ),
> +%		  "Level 1",
> +%                 big(
> +%                    big(
> +%                       small,
> +%		        "Level 3",
> +%			small
> +%                       ),
> +%		     "Level 2",
> +%		     small
> +%                    )).
> +%
> +%------------------------------------------------------------------------------%
> +% Width = 18, Line(s) = 16
> +%
> +% big(
> +%   big(
> +%     big(
> +%       small, 
> +%       "Level 3", 
> +%       small), 
> +%     "Level 2", 
> +%     small), 
> +%   "Level 1", 
> +%   big(
> +%     big(
> +%       small, 
> +%       "Level 3", 
> +%       small), 
> +%     "Level 2", 
> +%     small))
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 16, Line(s) = 16
> +% 
> +% big(
> +%   big(
> +%     big/3, 
> +%     "Level 2", 
> +%     small), 
> +%   "Level 1", 
> +%   big(
> +%     big/3, 
> +%     "Level 2", 
> +%     small))
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 50, Line(s) = 4
> +% 
> +% big(
> +%   big(big/3, "Level 2", small), 
> +%  "Level 1", 
> +%   big(big/3, "Level 2", small))
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 56, Line(s) = 4
> +% 
> +% big(
> +%   big(big(small, "Level 3", small), "Level 2", small), 
> +%   "Level 1", 
> +%   big(big(small, "Level 3", small), "Level 2", small))
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 30, Line(s) = 5
> +% 
> +% big(big/3, "Level 1", big/3)
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 33, Line(s) = 5
> +% 
> +% big(
> +%   big(big/3, "Level 2", small), 
> +%   "Level 1", 
> +%   big(big/3, "Level 2", small))
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 75, Line(s) = 1
> +% 
> +% big(big(big/3, "Level 2", small), "Level 1", big(big/3, "Level 2", small))
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 20, Line(s) = 10
> +% 
> +% big(
> +%   big(
> +%     big/3, 
> +%     "Level 2", 
> +%     small), 
> +%   "Level 1", 
> +%   big(
> +%     big/3, 
> +%     "Level 2", 
> +%     small))
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 40, Line(s) = 10
> +% 
> +% big(
> +%   big(
> +%     big(small, "Level 3", small), 
> +%     "Level 2", 
> +%     small), 
> +%   "Level 1", 
> +%   big(
> +%     big(small, "Level 3", small), 
> +%     "Level 2", 
> +%     small))
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 29, Line(s) = 1
> +% 
> +% big(big/3, "Level 1", big/3)
> +% 
> +%------------------------------------------------------------------------------%
> +% Width = 20, Line(s) = 1
> +% 
> +% big/3
> +% 
> +%------------------------------------------------------------------------------%
> +
> +:- module mdb__sized_pretty.
> +
> +:- interface.
> +
> +:- import_module std_util, int, string.
> +
> +	% This may throw an exception or cause a runtime abort if the term
> +	% in question has user-defined equality. 
> +	% The Limit is number of lines.
> +:- pred univ_to_string_line(univ::in, int::in, int::in, string::out) is det.
> +
> +%------------------------------------------------------------------------------%
> +
> +:- implementation.
> +
> +:- import_module list, require, assoc_list, pprint, bool.
> +
> +:- type no_measure_params --->	no_measure_params.
> +:- type measure_params
> +	--->	measure_params(int).	% This parameter specifies Linewidth
> +
> +
> +:- type maybe_deconstructed(T)
> +	--->	not_deconstructed
> +	;	deconstructed(
> +			string,		% Functor 
> +			int,		% Arity
> +			list(maybe(pair(T, size_annotated_term(T)))) % arguments
> +		).
> +
> +	% The exact type indicates the term has been fully deconstructed.
> +	% The at_least type indicates that the term has been deconstructed
> +	% upto the point where the specified limit was reached.
> +:- type size_annotated_term(T)
> +	--->	exact(
> +			univ,		% univ(Term)
> +			T,		% size of the term
> +			string,		% Functor
> +			int,		% Arity
> +			list(maybe(pair(T, size_annotated_term(T)))) % arguments
> +		)
> +	;	at_least(
> +			univ,		% univ(Term)
> +			T,		% size of the term upto the point
> +					% where it's deconstructed
> +			maybe_deconstructed(T)
> +		).
> +
> +:- typeclass measure(T) where [
> +	func max_measure(T, T) = T is det,
> +	func zero_measure = T is det,
> +	func compare_measures(T, T) = comparison_result is det
> +].
> +
> +:- typeclass measure_with_params(T, MeasureParams) <= measure(T) where [
> +	func add_measures(T, T, MeasureParams) = T is det,
> +	func subtract_measures(T, T, MeasureParams) = T is det,
> +
> +		% given a term, it's arity, and a limit, this method decides
> +		% the partial limit that each of the argument should be
> +		% given. It's arguments in order are term, measure parameter(s),
> +		% limit, arity, a flag, size of the Functor, partial limit,
> +		% adjusted limit, adjusted measure parameter(s).
> +		% Also a term is not deconstructed unless it has enough space
> +		% to print functor and the functors of it's arguments. But in
> +		% some cases this check is not needed that's why the booleen is
> +		% included.
> +	pred measured_split(univ::in, MeasureParams::in, T::in, int::in,
> +	     bool::in, T::out, maybe(T)::out, T::out, MeasureParams::out) is det
> +		
> +].
> +
> +%------------------------------------------------------------------------------%
> +	% When the space (to print the term) is given in number of lines there
> +	% is an inital check that has to be done. This is due to the fact that
> +	% size_count_split assumes that every term is part of a bigger term and
> +	% therefore assumes that a term will have a comma and a space after it.
> +	% This is not true for the biggest term (Head Term) therefore if the
> +	% Head Term is going to be printed on a single line then it should be
> +	% given a limit of character_count(LineWidth - 1) instead of
> +	% character_count(LineWidth - 3).
> +univ_to_string_line(Univ, LineWidth, Lines, String) :-
> +	Params = measure_params(LineWidth),
> +	deconstruct(univ_value(Univ), _, Arity, _),
> +	( 	Arity \= 0,
> +		Lines \= 0,
> +		(Lines - 1) // Arity = 0 
> +	->
> +		% "- 1" is to account for the newline character
> +		Limit = character_count(LineWidth - 1)
> +	;
> +		Limit = line_count(Lines)
> +	),
> +	annotate_with_size(Univ, Params, Limit, AnnotTerm),
> +	Doc = to_doc_sized(AnnotTerm),
> +	String = pprint__to_string(LineWidth, Doc).
> +
> +%------------------------------------------------------------------------------%
> +	% first_pass gives an idea of how much space each term takes
> +	% In this pass the space is unevenly distributed. First come first
> +	% served. And once the space runs out, the term is not deconstructed
> +	% further. 
> +	% In The Second pass the space is evenly distributed between
> +	% the terms and therefore the subterms are deconstructed evenly.
> +:- pred annotate_with_size(univ::in, MeasureParams::in, T::in,
> +	size_annotated_term(T)::out) is det
> +	<= measure_with_params(T, MeasureParams).
> +
> +annotate_with_size(Univ, Params, Limit, Size2) :-
> +	first_pass(Univ, Params, Limit, Size1),
> +	second_pass(Size1, Params, Limit, Size2).
> +
> +%------------------------------------------------------------------------------%
> +	
> +:- pred first_pass(univ::in, MeasureParams::in, T::in,
> +	size_annotated_term(T)::out) is det
> +	<= measure_with_params(T, MeasureParams).
> +
> +first_pass(Univ, Params, Limit, Size) :-
> +	deconstruct(univ_value(Univ), Functor, Arity, Args),	
> +	measured_split(Univ, Params, Limit, Arity, yes, FunctorSize, 
> +					Flag, NewLimit, NewParams),
> +	flag_with(Args, Flag, FlaggedUnivArgs),
> +	( (Arity \= 0, Flag = no) ->
> +		Exact0 = no
> +	;
> +		Exact0 = yes
> +	),
> +        annotate_args_with_size(FlaggedUnivArgs, NewParams, NewLimit, 
> +		FunctorSize, SoFar, Exact0, Exact, MaybeArgSizes),
> +	(
> +		Exact = no,
> +	        Size = at_least(Univ, SoFar,
> +	                        deconstructed(Functor, Arity, MaybeArgSizes))
> +	;
> +	        Exact = yes,
> +	        Size = exact(Univ, SoFar, Functor, Arity, MaybeArgSizes)
> +	).
> +
> +%------------------------------------------------------------------------------%
> +	% annotating the arguments.
> +:- pred annotate_args_with_size(assoc_list(maybe(T), univ)::in,
> +	MeasureParams::in, T::in, T::in, T::out, bool::in, bool::out,
> +	list(maybe(pair(T, size_annotated_term(T))))::out)
> +	is det <= measure_with_params(T, MeasureParams).
> +
> +annotate_args_with_size([], _, _, SoFar, SoFar, Exact, Exact, []).
> +annotate_args_with_size([Flag - Arg | FlaggedArgs], Params, Limit,
> +		SoFar0, SoFar, Exact0, Exact,
> +		[MaybeFlaggedSize | MaybeFlaggedSizes]) :-
> +	(
> +		Flag = yes(ArgLimit),
> +		AppliedArgLimit = max_measure(ArgLimit,
> +			subtract_measures(Limit, SoFar0, Params)),
> +		first_pass(Arg, Params, AppliedArgLimit, Size),
> +		MaybeFlaggedSize = yes(ArgLimit - Size),
> +		extract_size_from_annotation(Size) = ArgSize,
> +		SoFar1 = add_measures(SoFar0, ArgSize, Params),
> +		(
> +			Size = exact(_, _, _, _, _),
> +			Exact1 = Exact0
> +		;
> +			Size = at_least(_, _, _),
> +			Exact1 = no
> +		)
> +	;
> +		Flag = no,
> +		MaybeFlaggedSize = no,
> +		SoFar1 = SoFar0,
> +		Exact1 = Exact0
> +	),
> +	( compare_measures(SoFar1, Limit) = (>) ->
> +		SoFar = SoFar1,
> +		Exact = no,
> +		annotate_args_with_zero_size(FlaggedArgs, zero_measure,
> +			MaybeFlaggedSizes)
> +	;
> +		annotate_args_with_size(FlaggedArgs, Params, Limit,
> +			SoFar1, SoFar, Exact1, Exact, MaybeFlaggedSizes)
> +	).
> +
> +%------------------------------------------------------------------------------%
> +	% Annotates the arguments with zero limit.
> +:- pred annotate_args_with_zero_size(assoc_list(maybe(T), univ)::in, T::in,
> +	list(maybe(pair(T, size_annotated_term(T))))::out) is det <= measure(T).
> +
> +annotate_args_with_zero_size([], _, []).
> +annotate_args_with_zero_size([Flag - Univ | FlaggedArgs], ZeroMeasure,
> +		[FlaggedSize | FlaggedSizes]) :-
> +	(
> +		Flag = yes(ArgLimit),
> +		FlaggedSize = yes(ArgLimit -
> +			at_least(Univ, ZeroMeasure, not_deconstructed))
> +	;
> +		Flag = no,
> +		FlaggedSize = no
> +	),
> +	annotate_args_with_zero_size(FlaggedArgs, ZeroMeasure, FlaggedSizes).
> +
> +%------------------------------------------------------------------------------%
> +
> +:- func extract_size_from_annotation(size_annotated_term(T)) = T.
> +
> +extract_size_from_annotation(exact(_, Size, _, _, _)) = Size.
> +extract_size_from_annotation(at_least(_, Size, _)) = Size.
> +
> +%------------------------------------------------------------------------------%
> +
> +:- func extract_univ_from_annotation(size_annotated_term(T)) = univ.
> +
> +extract_univ_from_annotation(exact(Univ, _, _, _, _)) = Univ.
> +extract_univ_from_annotation(at_least(Univ, _, _)) = Univ.
> +
> +%------------------------------------------------------------------------------%
> +	% This predicate basically ensures that the arguments that
> +	% take up smaller "Space" than their fair share is fully
> +	% printed and the rest the Space is shared equally between
> +	% the other terms which could take up more than their share.
> +	% If a term can be fully printed within the given space,
> +	% ("exact" type) then the Term is not altered.
> +:- pred second_pass(size_annotated_term(T)::in, MeasureParams::in, T::in,
> +	size_annotated_term(T)::out) is det 
> +	<= measure_with_params(T, MeasureParams).
> +
> +second_pass(OldSizeTerm, Params, Limit, NewSizeTerm) :-
> +	(
> +    		OldSizeTerm = exact(_Univ, _Size, _, _Arity, _MaybeArgs),
> +		NewSizeTerm = OldSizeTerm
> +	;
> +    		OldSizeTerm = at_least(_Univ, _Size, not_deconstructed),
> +		NewSizeTerm = OldSizeTerm
> +	;
> +    		OldSizeTerm = at_least(Univ, _Size, deconstructed(Functor, 
> +			Arity,MaybeArgs)),
> +		measured_split(Univ, Params, Limit, Arity, yes, FSize, Flag,
> +			NewLimit, NewParams),
> +		( if Flag = yes(X) then
> +	    		ArgLimit = X,
> +	    		check_args(NewParams, MaybeArgs, ArgLimit, Passed, 
> +				Used),
> +			LeftOver = subtract_measures(NewLimit, Used, Params),
> +	    		measured_split(Univ, Params, LeftOver, Arity - Passed, 
> +				no, _, Flag2, _, _),
> +	    		( if Flag2 = yes(Y) then
> +	        		SplitLimit = Y,
> +	        		process_args(NewParams, MaybeArgs, ArgLimit, 
> +					SplitLimit, NewArgs, NewSize0),
> +				NewSize = add_measures(FSize, NewSize0, 
> +					NewParams),
> +				Result0 = list__map(check_if_exact, NewArgs),
> +    				list__remove_adjacent_dups(Result0, Result),
> +				( Result = [yes] ->
> +					NewSizeTerm = exact(Univ, NewSize, 
> +						Functor, Arity, NewArgs) 	
> +	        		;
> +					NewSizeTerm = at_least(Univ, NewSize, 
> +						deconstructed(Functor, Arity, 
> +						NewArgs))
> +				)
> +	    		else
> +	        		NewSizeTerm = at_least(Univ, FSize, 
> +					not_deconstructed)
> +	    		)
> +		else
> +	    	NewSizeTerm = at_least(Univ, FSize, not_deconstructed)
> +		)
> +	).
> +	
> +%------------------------------------------------------------------------------%
> +	% Given a list of size annotated terms(ie arguments) and a
> +	% Limit, this predicate returns the values "Passed" and 
> +	% "Used". Where "Passed" represents the number of terms that
> +	% obey the Limit and are fully represented("exact") and "Used"
> +	% represents the space that these terms take up.
> +:- pred check_args(MeasureParams::in, list(maybe(pair(T, size_annotated_term(T)
> +	)))::in, T::in, int::out, T::out) is det
> +	<= measure_with_params(T, MeasureParams).
> +
> +check_args(_, [], _, 0, zero_measure).
> +check_args(Params, [HeadArg | Rest], ArgLimit, Passed, Used) :-
> +	if HeadArg = yes(X) then
> +		X = _ - STerm,
> +		Size = extract_size_from_annotation(STerm), 
> +		( if STerm = exact(_, _, _, _, _) then
> +	    		( if compare_measures(ArgLimit, Size) = (<) then
> +	    			check_args(Params, Rest, ArgLimit, Passed, Used)
> +	    		else
> +	    			Passed = 1 + PassedRest,
> +				Used = add_measures(UsedRest, Size, Params),
> +	    			check_args(Params, Rest, ArgLimit, PassedRest, 
> +					UsedRest)
> +	    		)
> +		else
> +	    		check_args(Params, Rest, ArgLimit, Passed, Used)
> +		)
> +    	else
> +		check_args(Params, Rest, ArgLimit, Passed, Used).
> +
> +%------------------------------------------------------------------------------%
> +	% This predicate accepts a list of size annotated terms(paired
> +	% with a flag) and returns a list of the same type. This new
> +	% list would consist of the same number of terms as the other
> +	% but the terms which do not obey the limit or not fully 
> +	% represented would be annoted again with a new limit
> +	% (SplitLimit). The rest of the terms are left alone.
> +:- pred process_args(MeasureParams::in, 
> +	list(maybe(pair(T, size_annotated_term(T))))::in, T::in, T::in, 
> +	list(maybe(pair(T, size_annotated_term(T))))::out, T::out)
> +	is det <= measure_with_params(T, MeasureParams).
> +
> +process_args(_, [], _, _, [], zero_measure).
> +process_args(Params, [HeadArg | Rest], ArgLimit, SplitLimit, 
> +		[NewHeadArg | NewRest], SizeOut) :-
> +    	( if HeadArg = yes(X) then
> +		X = _ - STerm,
> +		Size = extract_size_from_annotation(STerm), 
> +        	Univ = extract_univ_from_annotation(STerm), 
> +		( 
> +			STerm = exact(_, _, _, _, _),
> +	    		(
> +				compare_measures(ArgLimit, Size) = (>)
> +			;
> +	    			compare_measures(ArgLimit, Size) = (=)
> +			)
> +		->
> +			NewHeadArg = HeadArg
> +		;
> +			NewHeadArg = yes(pair(SplitLimit, NewSTerm)),
> +			annotate_with_size(Univ, Params, SplitLimit, NewSTerm)
> +		)
> +    	else
> +		NewHeadArg = no
> +    	),
> +    	( NewHeadArg = yes(_ - Term) ->
> +		NewSize = extract_size_from_annotation(Term),
> +		SizeOut = add_measures(NewSize, RestSize, Params)
> +    	;
> +		SizeOut = RestSize
> +    	),
> +    	process_args(Params, Rest, ArgLimit, SplitLimit, NewRest, RestSize).
> +
> +%------------------------------------------------------------------------------%
> +	% checking if an size-annotated arg is an exact type (fully represented)
> +:- func check_if_exact(maybe(pair(T, size_annotated_term(T)))) = bool.
> +
> +check_if_exact(no) = no.
> +check_if_exact(yes(_ - Term)) = Result:-
> +	(
> +		Term = exact(_, _, _, _, _),
> +		Result = yes
> +	;
> +		Term = at_least(_, _, _),
> +		Result = no
> +	).	
> +
> +%------------------------------------------------------------------------------%
> +	% A function to convert a size annotated term to a 'doc' type,
> +	% a type defined in pprint.m.
> +:- func to_doc_sized(size_annotated_term(T)) = doc.
> +
> +to_doc_sized(at_least(Univ, _, not_deconstructed)) = Doc :-
> +	deconstruct(univ_value(Univ), Functor, Arity, _Args),
> +	Doc = text(Functor) `<>` text("/") `<>` poly(i(Arity)).
> +
> +to_doc_sized(at_least(_, _, deconstructed(Functor, Arity, MaybeArgs))) = Doc :-
> +	Doc = to_doc_sized_2(Functor, Arity, MaybeArgs).
> +
> +to_doc_sized(exact(_, _, Functor, Arity, MaybeArgs)) = Doc :-
> +	Doc = to_doc_sized_2(Functor, Arity, MaybeArgs).
> +
> +%------------------------------------------------------------------------------%
> +	% Assumes that every argument must be on a different line
> +	% or all of them should be on the same line.
> +:- func to_doc_sized_2(string, int, 
> +	list(maybe(pair(T, size_annotated_term(T))))) = doc.
> +
> +to_doc_sized_2(Functor, _Arity, []) = text(Functor).
> +
> +to_doc_sized_2(Functor, Arity, [HeadArg|Tail]) = Doc :-
> +    	Args = list__map(handle_arg, [HeadArg|Tail]),
> +    	list__remove_adjacent_dups(Args, NewArgs),
> +    	( NewArgs \= [nil] -> 
> +        	Doc = text(Functor) `<>` parentheses(group(nest(2, line `<>` 
> +			separated(id,comma_space_line, Args))))
> +    	;
> +        	Doc = text(Functor) `<>` text("/") `<>` poly(i(Arity))
> +    	).
> +	
> +%------------------------------------------------------------------------------%
> +
> +:- func handle_arg(maybe(pair(T,size_annotated_term(T)))) = doc.
> +
> +handle_arg(yes(_ - Arg_Term)) = to_doc_sized(Arg_Term). 
> +handle_arg(no) = nil.
> +
> +%------------------------------------------------------------------------------%
> +	% A predicate that creates an associated list of Univ and their
> +	% individual Limit
> +:- pred flag_with(list(univ)::in, maybe(T)::in,
> +	assoc_list(maybe(T), univ)::out) is det.
> +flag_with([], _, []).
> +flag_with([Arg | Args], Flag, [Flag - Arg | FlaggedArgs]) :-
> +	flag_with(Args, Flag, FlaggedArgs).
> +
> +%------------------------------------------------------------------------------%
> +	% functor_count is a representation where the size of a term
> +	% is measured by the number of function symbols.
> +
> +:- type functor_count
> +	--->	functor_count(int). 	% No of function symbols
> +
> +:- func add_functor_count(functor_count, functor_count, 
> +	no_measure_params) = functor_count.
> +
> +add_functor_count(functor_count(A), functor_count(B), _) = functor_count(A + B).
> +
> +:- func subtract_functor_count(functor_count, functor_count, 
> +	no_measure_params) = functor_count.
> +
> +subtract_functor_count(functor_count(A), functor_count(B), _) =
> +	functor_count(A - B).
> +
> +:- func compare_functor_count(functor_count, functor_count) = comparison_result.
> +
> +compare_functor_count(functor_count(A), functor_count(B)) = R :-
> +	compare(R, A, B).
> +
> +:- func max_functor_count(functor_count, functor_count) = functor_count.
> +
> +max_functor_count(functor_count(A), functor_count(B)) = functor_count(Max) :-
> +	int__max(A, B, Max).
> +
> +:- func zero_functor_count = functor_count.
> +
> +zero_functor_count = functor_count(0).
> +	
> +:- pred functor_count_split(univ::in, no_measure_params::in, functor_count::in,
> +	int::in, bool::in, functor_count::out, maybe(functor_count)::out,
> +	functor_count::out, no_measure_params::out) is det.
> +
> +functor_count_split(_, Params, functor_count(Limit), Arity, _, functor_count(1),
> +		Flag, functor_count(Limit), Params) :-
> +	( Arity = 0 ->
> +		Flag = no
> +	;
> +		( Limit =< (Arity + 1) ->			
> +			Flag = no
> +		;
> +			RoundUp = (Limit + Arity - 1) // Arity,
> +			Flag = yes(functor_count(RoundUp))
> +		)
> +	).
> +
> +:- instance measure(functor_count) where [
> +	func(compare_measures/2) is compare_functor_count,
> +	func(max_measure/2) is max_functor_count,
> +	func(zero_measure/0) is zero_functor_count
> +].
> +
> +:- instance measure_with_params(functor_count, no_measure_params) where [
> +	func(add_measures/3) is add_functor_count,
> +	func(subtract_measures/3) is subtract_functor_count,
> +	pred(measured_split/9) is functor_count_split
> +].
> +
> +
> +%------------------------------------------------------------------------------%
> +	% char_count is a representation where the size of a term is
> +	% measured by the number of characters.
> +
> +:- type char_count
> +	--->	char_count(int).	% No of characters
> +
> +:- func add_char_count(char_count, char_count, no_measure_params) = char_count.
> +
> +add_char_count(char_count(A), char_count(B), _) = char_count(A + B).
> +
> +:- func subtract_char_count(char_count, char_count, 
> +	no_measure_params) = char_count.
> +
> +subtract_char_count(char_count(A), char_count(B), _) =
> +	char_count(A - B).
> +
> +:- func compare_char_count(char_count, char_count) = comparison_result.
> +
> +compare_char_count(char_count(A), char_count(B)) = R :-
> +	compare(R, A, B).
> +
> +:- func max_char_count(char_count, char_count) = char_count.
> +
> +max_char_count(char_count(A), char_count(B)) = char_count(Max) :-
> +	int__max(A, B, Max).
> +
> +:- func zero_char_count = char_count.
> +
> +zero_char_count = char_count(0).
> +
> +:- pred char_count_split(univ::in, no_measure_params::in, char_count::in,
> +	int::in, bool::in, char_count::out, maybe(char_count)::out,
> +	char_count::out, no_measure_params::out) is det.
> +
> +char_count_split(Univ, Params, char_count(Limit), Arity, Check, 
> +		char_count(FunctorSize), Flag, char_count(Limit), Params) :-
> +	deconstruct(univ_value(Univ), Functor, _, Args),
> +	( Check = yes ->
> +		get_arg_length(Args, TotalLength, _)
> +	;
> +		TotalLength = 0
> +	),
> +	FunctorSize = string__length(Functor) + 2*(Arity),
> +	( Arity = 0 ->
> +		Flag = no
> +	;
> +		( Limit =< (FunctorSize + TotalLength) ->
> +			Flag = no
> +		;
> +			RoundUp = (Limit + Arity - FunctorSize) // Arity,
> +			Flag = yes(char_count(RoundUp))
> +		)
> +	).
> +
> +:- instance measure(char_count) where [
> +        func(compare_measures/2) is compare_char_count,
> +        func(max_measure/2) is max_char_count,
> +        func(zero_measure/0) is zero_char_count
> +].
> +
> +:- instance measure_with_params(char_count, no_measure_params) where [
> +        func(add_measures/3) is add_char_count,
> +        func(subtract_measures/3) is subtract_char_count,
> +        pred(measured_split/9) is char_count_split
> +].
> +
> +%------------------------------------------------------------------------------%
> +	% size_count is representation where the size of a term is
> +	% measured by number of lines or number of characters.
> +
> +:- type size_count
> +	--->	line_count(int)		% no of lines
> +	;	character_count(int).	% no of characters
> +
> +:- func add_size_count(size_count, size_count, measure_params) = size_count.
> +
> +add_size_count(character_count(A), character_count(B), Params) = Result :-
> +	Params = measure_params(LineWidth),
> +	CharSum = A + B,
> +	( CharSum > LineWidth ->
> +		Result = line_count(1)
> +	;
> +		Result = character_count(CharSum)
> +	).
> +
> +add_size_count(character_count(A), line_count(B), _) = Result :-
> +	( A > 0 -> 
> +		Result = line_count(B + 1)
> +	;
> +		Result = line_count(B)
> +	).
> +
> +add_size_count(line_count(A), character_count(B), _) = Result :-
> +	( B > 0 -> 
> +		Result = line_count(A + 1)
> +	;
> +		Result = line_count(A)
> +	).
> +
> +add_size_count(line_count(A), line_count(B), _) = line_count(A + B).
> +
> +	% Rounding up the Lines and subtracting works because we assume
> +	% that each argument is a different line or they are all on 
> +	% the same line. But this requires you to determine which case
> +	% likely to happen before hand. For example if a term is to be
> +	% on one line, you should do subtract_size_count(size_count(0, 
> +	% LineLength), size_count(0, arglength)) rather than
> +	% subtract_size_count(size_count(1, 0), size_count(0, arglength)).
> +	% The reason that this situation cannot be detected in this code is:
> +	% A term can be printed on a single line only if, all of it's 
> +	% arguments can be printed on the same line. And you cannot determine
> +	% which case is likely to happen in this code using the information 
> +	% it has. Therefore size_count_split determines which case is true 
> +	% (and changes the limit accordingly).

Now that you use the new size_count type, this comment no longer
matches the code.

> +:- func subtract_size_count(size_count, size_count,measure_params) = size_count.
> +
> +subtract_size_count(character_count(A), character_count(B), _) = Result :-
> +	CharDiff = A - B,
> +	( CharDiff < 0 ->
> +		Result = character_count(0)
> +	;
> +		Result = character_count(CharDiff)
> +	).
> +
> +subtract_size_count(character_count(A), line_count(B), _) = Result :-
> +	( B = 0 -> 
> +		Result = character_count(A)
> +	;
> +		Result = character_count(0)
> +	).
> +
> +subtract_size_count(line_count(A), character_count(B), _) = Result :-
> +	( B = 0 -> 
> +		Result = line_count(A)
> +	;
> +		( A - 1 >= 0 ->
> +			Result = line_count(A - 1)
> +		;
> +			Result = line_count(0)
> +		)
> +	).
> +
> +subtract_size_count(line_count(A), line_count(B), _) = Result :-
> +	( A - B >= 0 ->
> +		Result = line_count(A - B)
> +	;
> +		Result = line_count(0)
> +	).
> +
> +:- func compare_size_count(size_count, size_count) = comparison_result.
> +
> +compare_size_count(character_count(C1), character_count(C2)) = R :-
> +	compare(R, C1, C2).
> +
> +compare_size_count(character_count(_), line_count(_)) = (<).
> +
> +compare_size_count(line_count(_), character_count(_)) = (>).
> +
> +compare_size_count(line_count(L1), line_count(L2)) = R :-
> +	compare(R, L1, L2).
> +
> +:- func max_size_count(size_count, size_count) = size_count.
> +
> +max_size_count(A, B) = Max :-
> +	( compare_size_count(A, B) = (>) ->
> +		Max = A
> +	;
> +		Max = B
> +	).
> +
> +:- func zero_size_count = size_count.
> +
> +zero_size_count = character_count(0).
> +
> +	% We assume that all arguments have to be on separate lines, or 
> +	% the whole term should be printed on a single line.
> +:- pred size_count_split(univ::in, measure_params::in, size_count::in,
> +	int::in, bool::in, size_count::out, maybe(size_count)::out,
> +	size_count::out, measure_params::out) is det.
> +
> +size_count_split(Univ, Params, Limit, Arity, Check, FunctorSize, 
> +		Flag, NewLimit, NewParams) :-
> +	Params = measure_params(LineWidth),
> +    	deconstruct(univ_value(Univ), Functor, ActualArity, Args),
> +    	FSize = string__length(Functor) + 2*(ActualArity),

Put spaces around the `*'.

> +    	( Check = yes ->
> +    		get_arg_length(Args, TotalLength, MaxArgLength),
> +		int__max(MaxArgLength, (string__length(Functor) + 1), MaxLength)
> +    	;
> +    		TotalLength = 0,
> +		MaxLength = 0
> +    	), 
> +    	( 
> +		Arity = 0 
> +	->
> +		Flag = no,
> +    		FunctorSize = character_count(FSize),
> +		NewLimit = Limit,
> +		NewParams = Params
> +    	;
> +		(
> +			Limit = line_count(LineLimit),
> +			(LineLimit >= (Arity + 1), 
> +			(LineWidth - 2) >= MaxLength) 

The unnecessary parentheses don't help readability here.

> +		->
> +			Line = (LineLimit - 1) // Arity,
> +			Flag = yes(line_count(Line)),
> +			FunctorSize = line_count(1),
> +	    		NewLimit = Limit,
> +	    		NewParams = measure_params(LineWidth - 2)
> +		;
> +			Limit = line_count(LineLimit),
> +			LineLimit > 0, 
> +			LineWidth - 3 >= (FSize + TotalLength) 
> +		->
> +	    		Char = (LineWidth - 3 - FSize + Arity - 1) // Arity ,
> +	    		Flag = yes(character_count(Char)),
> +	    		FunctorSize = character_count(FSize),
> +	    		NewLimit = character_count(LineWidth - 3),
> +	    		NewParams = Params
> +   		;
> +			Limit = character_count(CharLimit),
> +			CharLimit >= (FSize + TotalLength)
> +		->
> +	   		Char = (CharLimit - FSize + Arity - 1)// Arity,
> +	   		Flag = yes(character_count(Char)),
> +	   		FunctorSize = character_count(FSize),
> +	   		NewLimit = Limit,
> +	   		NewParams = Params
> +		;
> +	   		Flag = no, 
> +	   		FunctorSize = 
> +				character_count(string__length(Functor) + 2),
> +	   		NewLimit = Limit, 
> +	   		NewParams = Params
> +		)
> +	).

It's hard to see why the magic numbers in the above code are used -- they
should atleast be documented in comments.

> +
> +:- instance measure(size_count) where [
> +	func(compare_measures/2) is compare_size_count,
> +	func(max_measure/2) is max_size_count,
> +	func(zero_measure/0) is zero_size_count
> +].
> +
> +:- instance measure_with_params(size_count, measure_params) where [
> +	func(add_measures/3) is add_size_count,
> +	func(subtract_measures/3) is subtract_size_count,
> +	pred(measured_split/9) is size_count_split
> +].
> +
> +%------------------------------------------------------------------------------%
> +	% This predicate determines how many characters it will take
> +	% to print the functors of the arguments. Also determines the
> +	% length of biggest functor.
> +:- pred get_arg_length(list(univ)::in, int::out, int::out) is det.
> +
> +get_arg_length([], 0, 0).
> +get_arg_length([HeadUniv | Rest], TotalLength, MaxLength) :-
> +	deconstruct(univ_value(HeadUniv), Functor, Arity, _),
> +	( Rest = [] ->
> +		Correction = 2
> +	;
> +		Correction = 3
> +	),
> +	( Arity = 0 -> 
> +		Length = string__length(Functor)
> +	;
> +		% 2 is added because if a term has arguments then the
> +		% shortest way to print it is "functor/Arity"
> +		% Assuming Arity is a single digit
> +		Length = string__length(Functor) + 2
> +	),
> +	TotalLength = Length + RestTotalLength,
> +	int__max((Length + Correction), RestMaxLength, MaxLength),
> +	get_arg_length(Rest, RestTotalLength, RestMaxLength).
> +
> +%------------------------------------------------------------------------------%
> Index: trace/mercury_trace_browse.c
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.c,v
> retrieving revision 1.18
> diff -u -r1.18 mercury_trace_browse.c
> --- trace/mercury_trace_browse.c	2000/11/23 02:01:07	1.18
> +++ trace/mercury_trace_browse.c	2001/01/23 05:33:23
> @@ -1,5 +1,5 @@
>  /*
> -** Copyright (C) 1998-2000 The University of Melbourne.
> +** Copyright (C) 1998-2001 The University of Melbourne.
>  ** This file may only be copied under the terms of the GNU Library General
>  ** Public License - see the file COPYING.LIB in the Mercury distribution.
>  */
> @@ -142,8 +142,8 @@
>  
>  bool
>  MR_trace_set_browser_param(MR_Bool print, MR_Bool browse, MR_Bool print_all,
> -		MR_Bool flat, MR_Bool pretty, MR_Bool verbose,
> -		const char *param, const char *value)
> +		MR_Bool flat, MR_Bool raw_pretty, MR_Bool verbose, 
> +		MR_Bool pretty, const char *param, const char *value)
>  {
>  	int			depth, size, width, lines;
>  	MR_Browse_Format	new_format;
> @@ -163,7 +163,7 @@
>  	{
>  		MR_TRACE_CALL_MERCURY(
>  			ML_BROWSE_set_param_depth(print, browse, print_all,
> -				flat, pretty, verbose, depth,
> +				flat, raw_pretty, verbose, pretty, depth,
>  				MR_trace_browser_persistent_state,
>  				&MR_trace_browser_persistent_state);
>  		);
> @@ -172,7 +172,7 @@
>  	{
>  		MR_TRACE_CALL_MERCURY(
>  			ML_BROWSE_set_param_size(print, browse, print_all,
> -				flat, pretty, verbose, size,
> +				flat, raw_pretty, verbose, pretty, size,
>  				MR_trace_browser_persistent_state,
>  				&MR_trace_browser_persistent_state);
>  		);
> @@ -181,7 +181,7 @@
>  	{
>  		MR_TRACE_CALL_MERCURY(
>  			ML_BROWSE_set_param_width(print, browse, print_all,
> -				flat, pretty, verbose, width,
> +				flat, raw_pretty, verbose, pretty, width,
>  				MR_trace_browser_persistent_state,
>  				&MR_trace_browser_persistent_state);
>  		);
> @@ -190,7 +190,7 @@
>  	{
>  		MR_TRACE_CALL_MERCURY(
>  			ML_BROWSE_set_param_lines(print, browse, print_all,
> -				flat, pretty, verbose, lines,
> +				flat, raw_pretty, verbose, pretty, lines,
>  				MR_trace_browser_persistent_state,
>  				&MR_trace_browser_persistent_state);
>  		);
> @@ -214,14 +214,16 @@
>  	if (streq(str, "flat")) {
>  		*format = MR_BROWSE_FORMAT_FLAT;
>  		return TRUE;
> -	} else if (streq(str, "pretty")) {
> -		*format = MR_BROWSE_FORMAT_PRETTY;
> +	} else if (streq(str, "raw_pretty")) {
> +		*format = MR_BROWSE_FORMAT_RAW_PRETTY;
>  		return TRUE;
>  	} else if (streq(str, "verbose")) {
>  		*format = MR_BROWSE_FORMAT_VERBOSE;
>  		return TRUE;
> +	} else if (streq(str, "pretty")) {
> +		*format = MR_BROWSE_FORMAT_PRETTY;
> +		return TRUE;
>  	}
> -
>  	return FALSE;
>  }
>  
> Index: trace/mercury_trace_browse.h
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.h,v
> retrieving revision 1.9
> diff -u -r1.9 mercury_trace_browse.h
> --- trace/mercury_trace_browse.h	2000/10/27 08:38:56	1.9
> +++ trace/mercury_trace_browse.h	2001/01/23 05:33:23
> @@ -1,5 +1,5 @@
>  /*
> -** Copyright (C) 1998-2000 The University of Melbourne.
> +** Copyright (C) 1998-2001 The University of Melbourne.
>  ** This file may only be copied under the terms of the GNU Library General
>  ** Public License - see the file COPYING.LIB in the Mercury distribution.
>  */
> @@ -29,8 +29,9 @@
>  
>  typedef enum {
>  	MR_BROWSE_FORMAT_FLAT,
> -	MR_BROWSE_FORMAT_PRETTY,
> -	MR_BROWSE_FORMAT_VERBOSE
> +	MR_BROWSE_FORMAT_RAW_PRETTY,
> +	MR_BROWSE_FORMAT_VERBOSE,
> +	MR_BROWSE_FORMAT_PRETTY
>  } MR_Browse_Format;
>  
>  /*
> @@ -58,8 +59,9 @@
>  ** Set browser parameters.
>  */
>  extern	bool	MR_trace_set_browser_param(MR_Bool print, MR_Bool browse,
> -			MR_Bool print_all, MR_Bool flat, MR_Bool pretty,
> -			MR_Bool verbose, const char *param, const char *value);
> +			MR_Bool print_all, MR_Bool flat, MR_Bool raw_pretty,
> +			MR_Bool verbose, MR_Bool pretty, const char *param, 
> +			const char *value);
>  
>  /*
>  ** Invoke an interactive query.
> Index: trace/mercury_trace_internal.c
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
> retrieving revision 1.97
> diff -u -r1.97 mercury_trace_internal.c
> --- trace/mercury_trace_internal.c	2001/01/18 03:01:48	1.97
> +++ trace/mercury_trace_internal.c	2001/01/23 05:33:23
> @@ -178,9 +178,10 @@
>  			const char *item);
>  static	bool	MR_trace_options_param_set(MR_Bool *print_set,
>  			MR_Bool *browse_set, MR_Bool *print_all_set,
> -			MR_Bool *flat_format, MR_Bool *pretty_format,
> -			MR_Bool *verbose_format, char ***words,
> -			int *word_count, const char *cat, const char *item);
> +			MR_Bool *flat_format, MR_Bool *raw_pretty_format,
> +			MR_Bool *verbose_format, MR_Bool *pretty_format, 
> +			char ***words, int *word_count, const char *cat, 
> +			const char *item);
>  static	void	MR_trace_usage(const char *cat, const char *item);
>  static	void	MR_trace_do_noop(void);
>  
> @@ -1093,21 +1094,23 @@
>  		MR_Bool			browse_set;
>  		MR_Bool			print_all_set;
>  		MR_Bool			flat_format;
> -		MR_Bool			pretty_format;
> +		MR_Bool			raw_pretty_format;
>  		MR_Bool			verbose_format;
> +		MR_Bool			pretty_format;
>  
>  		if (! MR_trace_options_param_set(&print_set, &browse_set,
> -				&print_all_set, &flat_format, &pretty_format,
> -				&verbose_format, &words, &word_count,
> -				"browsing", "set"))
> +				&print_all_set, &flat_format, 
> +				&raw_pretty_format, &verbose_format, 
> +				&pretty_format, &words, &word_count, "browsing",
> +				"set"))
>  		{
>  			; /* the usage message has already been printed */
>  		}
>  		else if (word_count != 3 ||
>  				! MR_trace_set_browser_param(print_set,
>  					browse_set, print_all_set, flat_format,
> -					pretty_format, verbose_format,
> -					words[1], words[2]))
> +					raw_pretty_format, verbose_format, 
> +					pretty_format, words[1], words[2]))
>  		{
>  			MR_trace_usage("browsing", "set");
>  		}
> @@ -2407,8 +2410,9 @@
>  static struct MR_option MR_trace_format_opts[] = 
>  {
>  	{ "flat",	FALSE,	NULL,	'f' },
> -	{ "pretty",	FALSE,	NULL,	'p' },
> +	{ "raw_pretty",	FALSE,	NULL,	'r' },
>  	{ "verbose",	FALSE,	NULL,	'v' },
> +	{ "pretty",	FALSE,	NULL,	'p' },
>  	{ NULL,		FALSE,	NULL,	0 }
>  };
>  
> @@ -2420,7 +2424,7 @@
>  
>  	*format = MR_BROWSE_DEFAULT_FORMAT;
>  	MR_optind = 0;
> -	while ((c = MR_getopt_long(*word_count, *words, "fpv",
> +	while ((c = MR_getopt_long(*word_count, *words, "frvp",
>  			MR_trace_format_opts, NULL)) != EOF)
>  	{
>  		switch (c) {
> @@ -2429,14 +2433,18 @@
>  				*format = MR_BROWSE_FORMAT_FLAT;
>  				break;
>  
> -			case 'p':
> -				*format = MR_BROWSE_FORMAT_PRETTY;
> +			case 'r':
> +				*format = MR_BROWSE_FORMAT_RAW_PRETTY;
>  				break;
>  
>  			case 'v':
>  				*format = MR_BROWSE_FORMAT_VERBOSE;
>  				break;
>  
> +			case 'p':
> +				*format = MR_BROWSE_FORMAT_PRETTY;
> +				break;
> +
>  			default:
>  				MR_trace_usage(cat, item);
>  				return FALSE;
> @@ -2451,8 +2459,9 @@
>  static struct MR_option MR_trace_param_set_opts[] = 
>  {
>  	{ "flat",	FALSE,	NULL,	'f' },
> -	{ "pretty",	FALSE,	NULL,	'p' },
> +	{ "raw_pretty",	FALSE,	NULL,	'r' },
>  	{ "verbose",	FALSE,	NULL,	'v' },
> +	{ "pretty",	FALSE,	NULL,	'p' },	
>  	{ "print",	FALSE,	NULL,	'P' },
>  	{ "browse",	FALSE,	NULL,	'B' },
>  	{ "print-all",	FALSE,	NULL,	'A' },
> @@ -2461,9 +2470,10 @@
>  
>  static bool
>  MR_trace_options_param_set(MR_Bool *print_set, MR_Bool *browse_set,
> -	MR_Bool *print_all_set, MR_Bool *flat_format, MR_Bool *pretty_format,
> -	MR_Bool *verbose_format, char ***words, int *word_count,
> -	const char *cat, const char *item)
> +	MR_Bool *print_all_set, MR_Bool *flat_format, 
> +	MR_Bool *raw_pretty_format, MR_Bool *verbose_format, 
> +	MR_Bool *pretty_format, char ***words, int *word_count, const char *cat,
> +	const char *item)
>  {
>  	int	c;
>  
> @@ -2471,11 +2481,12 @@
>  	*browse_set = FALSE;
>  	*print_all_set = FALSE;
>  	*flat_format = FALSE;
> -	*pretty_format = FALSE;
> +	*raw_pretty_format = FALSE;
>  	*verbose_format = FALSE;
> +	*pretty_format = FALSE;
>  
>  	MR_optind = 0;
> -	while ((c = MR_getopt_long(*word_count, *words, "PBAfpv",
> +	while ((c = MR_getopt_long(*word_count, *words, "PBAfrvp",
>  			MR_trace_param_set_opts, NULL)) != EOF)
>  	{
>  		switch (c) {
> @@ -2484,12 +2495,16 @@
>  				*flat_format = TRUE;
>  				break;
>  
> -			case 'p':
> -				*pretty_format = TRUE;
> +			case 'r':
> +				*raw_pretty_format = TRUE;
>  				break;
>  
>  			case 'v':
>  				*verbose_format = TRUE;
> +				break;
> +
> +			case 'p':
> +				*pretty_format = TRUE;
>  				break;
>  
>  			case 'P':
> 
> 
> --------------------------------------------------------------------------
> mercury-developers mailing list
> Post messages to:       mercury-developers at cs.mu.oz.au
> Administrative Queries: owner-mercury-developers at cs.mu.oz.au
> Subscriptions:          mercury-developers-request at cs.mu.oz.au
> --------------------------------------------------------------------------
> 

--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list