6.10 Object Printing

► |  | The Racket Reference

1 | Language Model
2 | Notation for Documentation
3 | Syntactic Forms
4 | Datatypes
5 | Structures
6 | Classes and Objects
7 | Units
8 | Contracts
9 | Pattern Matching
10 | Control Flow
11 | Concurrency and Parallelism
12 | Macros
13 | Input and Output
14 | Reflection and Security
15 | Operating System
16 | Memory Management
17 | Unsafe Operations
18 | Running Racket
| Bibliography
| Index

▼ | 6 | Classes and Objects

6.1 | Creating Interfaces
6.2 | Creating Classes
6.3 | Creating Objects
6.4 | Field and Method Access
6.5 | Mixins
6.6 | Traits
6.7 | Object and Class Contracts
6.8 | Object Equality and Hashing
6.9 | Object Serialization
6.10 | Object Printing
6.11 | Object, Class, and Interface Utilities
6.12 | Surrogates

On this page:

printable<%>
writable<%>

top ← prev up next →

#### 6.10`` Object Printing

To customize the way that a class instance is printed by print, write and display, implement the printable<%> interface.

> value printable<%> : interface?

The printable<%> interface includes only the custom-print, custom-write, and custom-display methods. The custom-print method accepts two arguments: the destination port and the current quasiquote depth as an exact nonnegative integer. The custom-write and custom-display methods each accepts a single argument, which is the destination port to write or display the object.

Calls to the custom-print, custom-write, or custom-display methods are like calls to a procedure attached to a structure type through the prop:custom-write property. In particular, recursive printing can trigger an escape from the call.

See prop:custom-write for more information. The printable<%> interface is implemented with interface* and prop:custom-write.

> value writable<%> : interface?

Like printable<%>, but includes only the custom-write and custom-display methods. A print request is directed to custom-write.
top ← prev up next →