Next: Filesystem Utilities Up: Ports Previous: Customizing Read

## Customizing Display, Write, and Print

Each output port has its own port display handler, port write handler, and port print handler. These handlers are invoked to output S-expressions to the port when the standard `display`, `write` or `print` procedure is applied to the port. A port display/write/print handler takes a two arguments: the value to be printed and the destination port. The handler's return value is ignored.

- `(port-display-handler output-port)` returns the current port display handler for output-port.
- `(port-display-handler output-port proc)` sets the display handler for output-port to proc.
- `(port-write-handler output-port)` returns the current port write handler for output-port.
- `(port-write-handler output-port proc)` sets the write handler for output-port to proc.
- `(port-print-handler output-port)` returns the current port print handler for output-port.
- `(port-print-handler output-port proc)` sets the print handler for output-port to proc.

The default port display and write handlers print Scheme expressions with MzScheme's built-in printer (see section 14.4). The default print handler calls the global port print handler (the value of the `global-port-print-handler` parameter; see section 9.4.1.2); the default global port print handler is the same as the default write handler.