[plt-scheme] Struct Printer

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Jun 19 11:36:31 EDT 2003

At 19 Jun 2003 10:10:13 -0500, Ed Cavazos wrote:
> Yeah, that's what I'm doing now:
> 
>         http://www.theworld.com/~proteus/print-dispatch.scm
> 
> This is fast because the print-dispatch function extracts the
> struct-type from a given object and does a lookup in the 'eq?' based
> hash table.
> 
> Unfortunately, the ability to get the struct-type requires a
> sufficiently senior inspector and I'd like this to also work with
> opaque structs. 

If you want to attach a printer to a struct type, you can create a
struct-type property that your custom printer uses, and that your
structure declarations install.

You'll have to use `make-struct-type' directly (instead of
`define-struct') to attach a property to the type, but you can write
your own macro, and `(lib "struct.ss" "syntax")' may help if you want a
macro that looks like `define-struct'.

It would make sense for the built-in printer to consult a standard
property. I still haven't done that because I've never solved to my
satisfaction the problems with cyclic structures.

Matthew



Posted on the users mailing list.