previous up next     contents index
Next: Pretty Printing Up: Libraries Previous: Match

Converted Printing

  Files: ``pconvert.ss'', ``pconvertu.ss'', ``pconverts.ss'', ``pconvertc.ss''
Requires: ``strings.ss'', ``functios.ss''
Opened form requires: ``stringu.ss'', ``functiou.ss''
Signature: mzlib:print-convert tex2html_wrap_inline2054
Unit:  mzlib:print-convert@, imports mzlib:string tex2html_wrap_inline2054 , mzlib:function tex2html_wrap_inline2054 , mzlib:print-convert-hooks tex2html_wrap_inline2054
Signature: mzlib:print-convert-hooks tex2html_wrap_inline2054
Unit:  mzlib:print-convert-hooks@, imports mzlib:print-convert tex2html_wrap_inline2054

This library defines routines for pretty-printing Scheme values as evaluateable S-expressions rather than readable S-expressions. The print-convert procedure does not print values; rather, it converts a Scheme value into another Scheme value such that the new value pretty-prints as a Scheme expression that evaluates to the original value. For example, (pretty-print (print-convert `(9 ,(box 5) #(6 7))) prints the literal expression (list 9 (box 5) (vector 6 7)) to the current output port.

The print-convert@ sigfunctor defines print-convert, build-share, get-shared, and print-convert-expr. The last three are used to print sub-expressions of a larger expression (potentially with shared structure).

The print-convert-hooks@ sigfunctor defines default hook functions that perform default operations. A new functor using the signature print-convert-hooks tex2html_wrap_inline2054 can be defined to instatiate new hooks. If functors are not used, these hooks can be redefined using define or set!.

 

(build-share expr) (procedure)

Takes an expression and computes sharing information used for printing the expression. The return value is an opaque structure that can be passed back into get-shared or print-convert-expr.

 

(build-share-hook expr sub-share-checker) (procedure)

This procedure is meant to be redefined. It is called by print-convert and build-share-hook when the Expr value is opaque, and therefore assumed to be atomic. If the value is actually not atomic, the hook procedure should apply sub-share-checker to each sub-value in expr. A build-share-hook procedure must work together with a print-convert-hook procedure.

 

(build-share-name-hook expr) (procedure)

This procedure is meant to be redefined. It is called by print-convert and build-share to assciate a name with a value when the value is shared. If the return value is #f, a name of the form ``<n>'' (where n is an integer) is used.

 

(current-read-eval-convert-print-prompt str) (procedure)

Sets the prompt used by install-converting-printer. If this procedure is called with no arguments, the current prompt string is returned.

 

(get-shared share-info cycles-only?) (procedure)

The shared-info value must be a result from build-share. The procedure returns a list matching identifier to shared expressions within the value passed to build-share. For exmaple, (get-shared (build-share (shared ([a (cons 1 b)][b (cons 2 a)]) a))) might return the list ((<1> (cons 1 <2>)) (<2> (cons 2 <1>))). The cycles-only? argument is optional and defaults to #f; if it is not #f, get-shared returns only information about cycles.

 

(install-converting-printer) (procedure)

Sets the current print handler to print values using print-convert. The current read handler is also set to use the prompt returned by current-read-eval-convert-print-prompt.

 

(print-convert expr cycles-only?) (procedure)

Converts the value expr. If cycles-only? is not #f, then only circular objects are printed; the cycles-only? argument is optional and defaults to #f.

 

(print-convert-expr share-info expr) (procedure)

Converts the expression expr using sharing information share-info previously returned by build-share for a value containing expr. If the most recent call to get-shared with share-info requested information only for cycles, then print-convert-expr will only display sharing among values for cycles, rather than showing all value sharing.

 

(print-convert-hook expr sub-converter) (procedure)

This procedure is meant to be redefined. It is called by print-convert and print-convert-expr when no transformations otherwise apply to the expr value for printing. The sub-converter argument takes an expression and expands it, in case the hook needs to expand parts of the expr value. A print-convert-hook procedure should work together with a build-share-hook procedure.


previous up next     contents index
Next: Pretty Printing Up: Libraries Previous: Match

PLT