For review: Term display helper

Peter Schachte pets at students.cs.mu.OZ.AU
Wed Mar 4 14:24:05 AEDT 1998


On Fri, 27 Feb 1998, Waye-Ian CHIEW wrote:

First let me suggest a quick look at library/portray.nl for an example
implementation of a much simpler version of this.  From the top of this
file, here are the capabilities of this package:
	
	You can control the depth limit, and separately the limit on
	the lengths of lists and the number of arguments shown for
	high-arity terms.  You can also "turn off" certain arguments
	of certain terms, based on the functor of the term, or even
	turn off the whole term.  Finally, you can define your own
	print methods for terms if you like, so lists of character
	codes can be printed as double-quoted strings, and maps can be
	printed out as associations.  Both of these are provided as
	examples.

> X   For example, if the user preferred the type rgb to be collapsed,
> X   then the displayer helper would display the term:
> X      shape(vector(1.2, 0, 15.8), colour(rgb(15, 0, 12), hsb(140, 18, 19))).
> X
> X   In flat format as:
> X	 shape(vector(1.2, 0, 15.8), colour(rgb/3, hsb(140, 18, 19))).
> X
> X   Pretty printed as:
> X	 shape(vector(1.2, 
> X		      0, 
> X		      15.8), 
> X	       colour(rgb/3, 
> X		      hsb(140, 
> X			  18, 
> X			  19))).

The display of `rgb/3' is ambiguous.  I suggest you print elided terms
using some special syntax, such as `<rgb/3>'.

> X   For example, the term which would be displayed pretty printed as:
> X
> X	 f(cons(1,
> X	        cons(2,
> X                     cons(3,
> X                          nil))),
> X	   map(map(leaf, 
> X		   pair("date", 188), 
> X		   leaf), 
> X	       pair("weight", 12),
> X	       leaf))
> X
> X   Would be much more meaningful displayed as:
> X
> X	 f([1, 
> X	    2, 
> X	    3],
> X	   map("date" -> 188,
> X	       "weight" -> 12)).

The syntax of the map term is ambiguous.  I suggest printing "special"
format terms in some special way.  In portray.nl, I have code that prints
maps like:

	map{"date" -> 188, "weight" -> 12}

Note the use of curley brackets instead of parentheses.  Maybe square
brackets would be better, as the distinction is clearer.  In any case,
using the type name as a functor isn't always desirable.

> X   For example:
> X   
> X      A list type:
> X
> X         :- type list(T)        --->
> X                        cons(T, list(T))
> X                ;       nil.
> X                
> X      
> X         cons   -> block([subterm(show([1])), show([2])]).
> X
> X         nil    -> nop.

Where do the "[", "," and "]" get printed out?  I don't understand how
this works.  If I wanted to use infix dot notation (eg, [a,b,c] would
be printed as a.b.c.[]), what would I write?

Handling this sort of thing is tricky, because when you find the "top"
of the list, you want to print "[", then print the head of the list,
then enter a recursive predicate that for each element prints a ","
followed by the element (but knows not to print the "[" again), and
finally print the "]".  This sort of thing is reasonably common; your
map example follows the same schema.  Even compound follow this
pattern.  It may be worth adding direct support for this schema.


-Peter Schachte			| ADA, n.: Something you need only know the
pets at cs.mu.OZ.AU		| name of to be an Expert in Computing. Useful
http://www.cs.mu.oz.au/~pets/	| in sentences like, "We had better develop an
PGP key available on request	| ADA awareness." 




More information about the developers mailing list