[plt-scheme] print-object equivalent

From: Grant Rettke (grettke at acm.org)
Date: Mon Oct 13 15:26:59 EDT 2008

On Mon, Oct 13, 2008 at 11:55 AM, Dave Gurnell <d.j.gurnell at gmail.com> wrote:
> This was a quite recent addition to PLT. Someone can correct me if I'm
> wrong, but I think you have to be running a Subversion build from some time
> in the last month for this to work.
> All you have to do is implement the printable<%> interface and the
> custom-display and custom-write methods in your class. Untested example
> follows:

Thanks Dave. Here is the tested version:

#lang scheme
(define my-class%
  (class* object% (printable<%>)
    ; output-port -> void
    (define/public (custom-display out)
      (display "[Instance of my-class%]" out))
    ; output-port -> void
    (define/public (custom-write out)
      (display "[Instance of my-class%]" out))

(define c (make-object my-class%))

(printf "The object c is an: ~a~n" c)

Posted on the users mailing list.