[m-dev.] Contribution: Pretty Printing Library

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Apr 12 14:27:27 AEST 2000


On 12-Apr-2000, Mark Anthony BROWN <dougl at cs.mu.OZ.AU> wrote:
> [Ralph writes:]
> >     % Convert arbitrary types to docs.  This requires std_util__functor/3
> >     % to work on all components of the object being converted.  The second
> >     % version places a maximum depth on terms which are otherwise truncated
> >     % to `...'.
> >     %
> >     % XXX This throws an exception if the term in question has user-defined
> >     % equality.
> 
> Actually, it causes a fatal error in the Mercury runtime system,
> so there is not much you can do about it at this stage.  In any
> case, I wouldn't worry about that too much, since that is also what
> io__write, io__print, etc, do.
> 
> In general, if a term is to be printed out (using io__write,
> pprint__write, etc) then it needs to have a canonical representation,
> or else the procedure needs to be cc_multi.  In this context, the best
> way for a user to provide a canonical representation for a type with
> user-defined equality is to do this as part of a customised document
> generator, IMHO.
> 
> So my suggestion for what to do here is to change the last sentence to:
> 
>      % This causes a runtime abort if the term in question has user-defined
>      % equality.
> 
> I think this doesn't need an XXX, since it is reasonable to make this
> actually part of the specification, not just an unimplemented feature.

Well, if it were an exception, then removing the XXX would be fine.
But if it is a runtime abort, then I think the XXX is justified:
providing features which can cause unrecoverable program failure
in a way that the caller can't easily avoid is an invitation to
trouble.

I think the specification should allow for the possibility that
the behaviour may change in the future:

      % This may throw an exception or cause a runtime abort
      % if the term in question has user-defined equality.

> >     % Convert docs to pretty printed strings.
> >     % The int argument specifies a page width.
> 
> s/page width/line width/
> 
> It may not be headed for the printer.  ;-)

It would also be a good idea to specify the units
(pixels? inches? centimeters? characters?).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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