Next: , Previous: Value History, Up: Guile Modules


6.7 Pretty Printing

The module (ice-9 pretty-print) provides the procedure pretty-print, which provides nicely formatted output of Scheme objects. This is especially useful for deeply nested or complex data structures, such as lists and vectors.

The module is loaded by simply saying.

     (use-modules (ice-9 pretty-print))

This makes the procedure pretty-print available. As an example how pretty-print will format the output, see the following:

     (pretty-print '(define (foo) (lambda (x)
     (cond ((zero? x) #t) ((negative? x) -x) (else
     (if (= x 1) 2 (* x x x)))))))
     -|
     (define (foo)
       (lambda (x)
         (cond ((zero? x) #t)
               ((negative? x) -x)
               (else (if (= x 1) 2 (* x x x))))))
— Scheme Procedure: pretty-print obj [port] [keyword-options]

Print the textual representation of the Scheme object obj to port. port defaults to the current output port, if not given.

The further keyword-options are keywords and parameters as follows,

#:display? flag
If flag is true then print using display. The default is #f which means use write style. (see Writing)
#:per-line-prefix string
Print the given string as a prefix on each line. The default is no prefix.
#:width columns
Print within the given columns. The default is 79.