Next: , Previous: , Up: Printing Scheme   [Contents][Index]


4.12.1 Generic-Write

(require 'generic-write)

generic-write is a procedure that transforms a Scheme data value (or Scheme program expression) into its textual representation and prints it. The interface to the procedure is sufficiently general to easily implement other useful formatting procedures such as pretty printing, output to a string and truncated output.

Procedure: generic-write obj display? width output
obj

Scheme data value to transform.

display?

Boolean, controls whether characters and strings are quoted.

width

Extended boolean, selects format:

#f

single line format

integer > 0

pretty-print (value = max nb of chars per line)

output

Procedure of 1 argument of string type, called repeatedly with successive substrings of the textual representation. This procedure can return #f to stop the transformation.

The value returned by generic-write is undefined.

Examples:

(write obj) ≡ (generic-write obj #f #f display-string)
(display obj) ≡ (generic-write obj #t #f display-string)

where

display-string ≡
(lambda (s) (for-each write-char (string->list s)) #t)