[m-rev.] Performance, layout and code improvements to pprint.m
Ralph Becket
rafe at cs.mu.OZ.AU
Thu Nov 1 10:56:10 AEDT 2001
Mark Brown, Thursday, 1 November 2001:
> On 29-Oct-2001, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> >
> > library/pprint.m:
> > - Tidied up the code somewhat, including the removal of several
> > now-useless functions.
> > - Fixed a performance bug in be//3 where what looked tail recursion
>
> s.be//3.be/3.
I've always adopted the convention that p//N means "p with N explicit
arguments + 2 DCG arguments". If that's not widely recognised I'll
change it to `be/5'.
> >
> > + % A group doc gives the pretty printer a choice: if
> > + % the doc can be printed without line wrapping then
> > +
>
> This comment is unfinished.
Finished with
% A group doc gives the pretty printer a choice: if
% the doc can be printed without line wrapping then
% it does so (all line, label, nest and group
% directives within the group are ignored); otherwise
% the pretty printer treats the group body literally,
% although nested group docs remain as choice points.
> > % A group doc may be flattened out in the sense
> > % described for line, above, at the discretion of the
> > % pretty printer. A group doc, therefore, defines a
> > @@ -216,14 +219,40 @@
> > :- func brackets(doc) = doc.
> > :- func braces(doc) = doc.
> >
> > - % separated(PP, Sep, [X1,...,Xn]) =
> > - % PP(X1) `<>` (Sep `<>` ... (Sep `<>` PP(Xn)) ... )
> > + % packed(Sep, [X1, X2, .., Xn]) = G1 `<>` G2 `<>` .. `<>` Gn where
> > + % Gi = group(line `<>` Xi `<>` Sep), except for Gn where
> > + % Gn = group(line `<>` Xn).
> > + %
> > + % For the singleton list case, packed(Sep, [X]) = group(line `<>` X).
> > + %
> > + % The resulting doc tries to pack as many items on a line as
> > + % possible.
> > %
> > - % Note that if you want to pack as many things on one
> > - % line as possible with some sort of separator, the
> > - % following example illustrates a suitable idiom:
> > +:- func packed(doc, list(doc)) = doc.
> > +
> > + % A variant of the above whereby only the first N elements of
> > + % the list are formatted and the rest are replaced by a single
> > + % ellipsis.
> > + %
> > +:- func packed(int, doc, list(doc)) = doc.
> > +
> > + % packed_cs(Xs) = packed(comma_space, Xs).
>
> I'm not sure this abbreviation is a good idea, even though I'd expect
> this variant to be used fairly often. It doesn't achive the aim of
> making code more readble, IMHO. Can you think of a non-abbreviated
> name which concisely describes the resulting document? I'm thinking
> of something like packed_list, although that could be slightly
> misleading, since it might suggest a list in Mercury syntax.
I considered packed_list, but rejected it for the reasons you describe.
I'm open to suggestions, though.
> > pretty_printing.m
> > ===================================================================
>
> If you 'cvs add' new files before creating the diff, then recent
> versions of cvs will create a diff of these new files against /dev/null.
> This saves you having to manually include all the added files.
Righto.
Are you happy enough with the change modulo finishing the comment above
that I can check this in?
Cheers,
Ralph
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list