[plt-scheme] print-object equivalent
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))
(super-new)))
(define c (make-object my-class%))
(printf "The object c is an: ~a~n" c)