[plt-scheme] print-object equivalent
Hi Deep,
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:
(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))))
Cheers,
-- Dave
> I have merrily hacking using DrScheme and wanted to know if theres
> some way to define what controls the printed representation of objects
> of a given class. I am looking for plt schemes equivalent to the
> print-
> object generic function from lisp.
>
> Also I was looking for advice to implement logging in an application
> which uses objects. Is it possible using some metaclass based magic to
> get all defined classes in my application to log all messages they
> receive ?
>
> PS: Thanks for the great *searchable* documentation that comes with
> DrScheme. It makes DrScheme one of the most productive environments
> ive used in a long time.