Google

PLT MzLib: Libraries Manual


pretty.ss: Pretty Printing

(pretty-display v [port])      PROCEDURE

Same as pretty-print, but v is printed like display instead of like write.

(pretty-print v [port])      PROCEDURE

Pretty-prints the value v using the same printed form as write, but with newlines and whitespace inserted to avoid lines longer than (pretty-print-columns), as controlled by (pretty-print-current-style-table). The printed form ends in a newline unless the pretty-print-columns parameter is set to 'infinity.

If port is provided, v is printed into port; otherwise, v is printed to the current output port.

In addition to the parameters defined by the pretty library, pretty-print conforms to the print-graph, print-struct, and print-vector-length parameters.

(pretty-print-current-style-table style-table [procedure])      

Parameter that holds a table of style mappings. See pretty-print-extend-style-table.

(pretty-print-columns [width])      PROCEDURE

Parameter that sets the default width for pretty printing to width and returns void. If no width argument is provided, the current value is returned instead.

If the display width is 'infinity, then pretty-printed output is never broken into lines, and a newline is not added to the end of the output.

(pretty-print-depth [depth])      PROCEDURE

Parameter that sets the default depth for recursive pretty printing to depth and returns void. If no depth argument is provided, the current value is returned instead. A depth of 0 indicates that only simple values are printed; Scheme values within other values (e.g. the elements of a list) are replaced with ``...''.

(pretty-print-display-string-handler [f])      PROCEDURE

Parameter that sets the procedure for displaying final strings to a port to output pretty-printed values. The default handler is the default port display handler (see section 11.2.5 in PLT MzScheme: Language Manual).

(pretty-print-exact-as-decimal [as-decimal?])      PROCEDURE

Parameter that determines how exact non-integers are printed. If the parameter's value is #t, then an exact non-integer with a decimal representation is printed as a decimal number instead of a fraction. The initial value is #f.

(pretty-print-extend-style-table style-table symbol-list like-symbol-list)      PROCEDURE

Creates a new style table by extending an existing style-table, so that the style mapping for each symbol of like-symbol-list in the original table is used for the corresponding symbol of symbol-list in the new table. The symbol-list and like-symbol-list lists must have the same length. The style-table argument can be #f, in which case with default mappings are used for the original table (see below).

The style mapping for a symbol controls the way that whitespace is inserted when printing a list that starts with the symbol. In the absence of any mapping, when a list is broken across multiple lines, each element of the list is printed on its own line, each with the same indentation.

The default style mapping includes mappings for the following symbols, so that the output follows popular code-formatting rules:

lambda case-lambda 
define define-macro define-syntax 
let letrec let* 
let-syntax letrec-syntax 
let-values letrec-values let*-values 
let-syntaxes letrec-syntaxes 
begin begin0 do 
if set! set!-values 
unless when 
cond case and or 
module 
syntax-rules syntax-case letrec-syntaxes+values 
import export require require-for-syntax provide link 
public private override rename inherit field init 
shared send class instantiate make-object 

(pretty-print-handler v)      PROCEDURE

Pretty-prints v if v is not void or prints nothing otherwise. Pass this procedure to current-print to install the pretty printer into the read-eval-print loop.

(pretty-print-print-hook [hook])      PROCEDURE

Parameter that sets the print hook for pretty-printing to hook. If hook is not provided, the current hook is returned.

The print hook is applied to a value for printing when the sizing hook (see pretty-print-size-hook) returns an integer size for the value.

The print hook receives three arguments. The first argument is the value to print. The second argument is a Boolean: #t for printing like display and #f for printing like write. The third argument is the destination port.

(pretty-print-print-line [liner])      PROCEDURE

Parameter that sets a procedure for printing the newline separator between lines of a pretty-printed value. The liner procedure is called with four arguments: a new line number, an output port, the old line's length, and the number of destination columns. The return value from liner is the number of extra characters it printed at the beginning of the new line.

The liner procedure is called before any characters are printed with 0 as the line number and 0 as the old line length; liner is called after the last character for a value is printed with #f as the line number and with the length of the last line. Whenever the pretty-printer starts a new line, liner is called with the new line's number (where the first new line is numbered 1) and the just-finished line's length. The destination columns argument to liner is always the total width of the destination printing area, or 'infinity if pretty-printed values are not broken into lines.

The default liner procedure prints a newline whenever the line number is not 0 and the column count is not 'infinity, always returning 0. A custom liner procedure can be used to print extra text before each line of pretty-printed output; the number of characters printed before each line should be returned by liner so that the next line break can be chosen correctly.

(pretty-print-show-inexactness [explicit?])      PROCEDURE

Parameter that determines how inexact numbers are printed. If the parameter's value is #t, then inexact numbers are always printed with a leading #i. The initial value is #f.

(pretty-print-style-table? v)      PROCEDURE

Returns #t if v is a style table,#f otherwise.

(pretty-print-post-print-hook [hook])      PROCEDURE

Parameter that sets a procedure to be called just after an object is printed. The hook receives two arguments: the object and the output port.

(pretty-print-pre-print-hook [hook])      PROCEDURE

Parameter that sets a procedure to be called just before an object is printed. The hook receives two arguments: the object and the output port.

(pretty-print-size-hook [hook])      PROCEDURE

Parameter that sets the sizing hook for pretty-printing to hook. If hook is not provided, the current hook is returned.

The sizing hook is applied to each value to be printed. If the hook returns #f, then printing is handled internally by the pretty-printer. Otherwise, the value should be an integer specifying the length of the printed value in characters; the print hook will be called to actually print the value (see pretty-print-print-hook).

The sizing hook receives three arguments. The first argument is the value to print. The second argument is a Boolean: #t for printing like display and #f for printing like write. The third argument is the destination port. The sizing hook may be applied to a single value multiple times during pretty-printing.

(pretty-print-.-symbol-without-bars [bool])      PROCEDURE

Parameter that controls the printing of the symbol whose print name is just a period. If set to a true value, it is printed as only the period. If set to a false value, it is printed as a period with vertical bars surronding it.