[m-dev.] User-controlled pretty-printing

Peter Schachte schachte at csse.unimelb.edu.au
Thu Dec 14 13:57:39 AEDT 2006

On Thu, Dec 14, 2006 at 09:44:15AM +1100, Ralph Becket wrote:
> So, what we want is:
> - the ability to navigate to a subterm using an abstract address
>   e.g., go to the "3rd list item" rather than navigating through cons
>   cells with "2/2/2/1";

How about navigating by unfolding recursive types and counting only
non-recursive arguments?  This means you select the 3rd list element
by saying just "3."  For a binary tree type, "3" would specify the
third non-recursive argument in a left-to-right depth-first traversal.
By "non-recursive argument" I mean an argument of the term with
different type than the term itself.  So for a type

	tree(T) ---> empty ; tree(tree(T), T, tree(T)).

we'd only count the second argument of the tree/3 term.  In this case,
3 would specify the third element in a depth-first left-to-right
traversal of the tree.  It would be similar for a 2-3-4 tree, except
that the internal nodes come in three different flavours, and
different flavours have different numbers of non-recursive arguments
to count.

> - the ability to specify how certain terms are printed
>   e.g., "print only the first and second fields of `foo/7' terms".

If you do this, then you should probably only count terms that are
actually shown when interpreting a number specifying a term.  Eg, if
you're only showing the odd arguments of a term, then "3" should
actually specify the 5th argument.

The big shortcoming of this is in handling types with a real
pretty-printer defined.  Eg, you'd really rather display at a 2-3-4
tree something like

	"apple" -> big_term(...)
	"banana" -> big_term(...)
	"orange" -> big_term(...)

In this case, you'd probably be OK.  You'd specify "4" to examine the
mapping for "banana," which seems intuitive enough.  But other
pretty-printers may exhibit little relation between the order subterms
are shown and the order they appear in a left-to-right traversal of
the term.

Let's face it:  what you really want is to be able to click on a
subterm with the mouse.

Peter Schachte              School is a strange, artificial thing, half
schachte at cs.mu.OZ.AU        sterile and half feral.
www.cs.mu.oz.au/~schachte/      -- Paul Graham 
Phone: +61 3 8344 1338      
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au

More information about the developers mailing list