- set-record-printer! NAME PROCEDUREprocedure
- set! (record-printer NAME) PROCEDUREprocedure
Defines a printing method for record of the type NAME by associating a procedure with the record type. When a record of this type is written using display, write or print, then the procedure is called with two arguments: the record to be printed and an output-port.
(define-record-type foo (make-foo x y z) foo? (x foo-x) (y foo-y) (z foo-z)) (define f (make-foo 1 2 3)) (set-record-printer! foo (lambda (x out) (fprintf out "#,(foo ~S ~S ~S)" (foo-x x) (foo-y x) (foo-z x)))) (define-reader-ctor 'foo make-foo) (define s (with-output-to-string (lambda () (write f)))) s ==> "#,(foo 1 2 3)" (equal? f (with-input-from-string s read))) ==> #t