Commit Graph

55 Commits

Author SHA1 Message Date
Ralph Becket
953966bfe7 Improve the pretty printer's output for various types.
Estimated hours taken: 2
Branches: main

Improve the pretty printer's output for various types.  This makes
the debugger's pretty format much more useful.

library/pprint.m:
	Extended the pretty printer's to_doc/2 function to format
	lists, tuples and maps more readably.  Lists now appear
	as [a, b, c, ...], tuples as {a, b, c}, and maps as
	map(key1 -> value1, key2 -> value2, ...).  Ellipsis
	represents the remainder of a list of map where the depth
	limit has been reached.
2001-04-26 14:55:13 +00:00
Ralph Becket
3b9872cb0c Fixed the performance problem with the pretty printer; runtime
Estimated hours taken: 2

Fixed the performance problem with the pretty printer; runtime
should now be linear in the size of the input (the previous
version suffered from being a somewhat optimistic direct
transliteration of a Haskell program).

Also made one or two other minor changes.

library/pprint.m
	Changed the formatting decision procedure from
	flatten/1 + be/3 + fits/2 (short and sweet and
	works fine if you have laziness) to a new set of
	predicates flattening_works/3 + fits_flattened/3 +
	fits_on_rest/2 which ensure linear run-time
	behaviour and reduce structure creation.

	In doing so, removed Mark's optimisation of flatten
	(it was only a partial solution, alas).

	Changed to_doc/[1,2] so that closing parentheses
	don't appear on separate lines, so as to reduce
	the amount of vertical space consumed.

	Changed to_doc/2 so that `foo/N' is output rather
	than `foo(...)' when the depth limit is reached.

	Extended the comment for separated/3 to include a
	useful idiom and changed the implementation so that
	docs created by separated/3 nest to the right.

	Simplified the definition of word_wrapped/1 to use
	the above idiom.

	Changed the core function be/3 into a predicate be/5
	to use an accumulator and hence be tail recursive.
	This made it possible to do away with the complex
	definition of simple_doc and replace it with just a
	list of strings.  This in turn simplified the
	definition of layout/2.
2000-05-25 13:14:02 +00:00
Mark Brown
004415b684 Fix a bug which led to exponential worst-case performance.
Estimated hours taken: 3

library/pprint.m:
	Fix a bug which led to exponential worst-case performance.
	We check the size of a document as it is being flattened,
	rather than afterward.  This means failure can occur earlier,
	which usually avoids an unnecessary recursive call while
	processing 'GROUP' documents.
2000-05-23 07:43:38 +00:00
Fergus Henderson
8c32ba927b Fix a bug: there was an infinite loop in the code for `to_doc'.
Estimated hours taken: 0.5

library/pprint.m:
	Fix a bug: there was an infinite loop in the code for `to_doc'.
	The recursive call to convert the term's arguments was
	happening even in the case where the term had no arguments.
2000-05-09 13:06:47 +00:00
Ralph Becket
43cc364d03 Added a new pretty-printer module to the standard library.
Estimated hours taken: 10

library/pprint.m:
	Added a new pretty-printer module to the standard library.  The
	pretty printer is an almost direct transliteration of the one
	described by Wadler in his paper "A Prettier Printer".  It is
	pretty much equivalent in power to Hughes' classic design, but
	superior in design in a number of respects (for one thing, it's
	much simpler).  Fairly extensive documentation can be found in
	the leader comment of the module itself and in its interface
	section.

library/library.m:
	Added pprint to import set.

NEWS:
	Mentioned addition of the new module under "Changes to the standard
	library".
2000-05-03 09:56:46 +00:00