[plt-scheme] Inspectors in mzscheme

From: Felix Klock's PLT scheme proxy (pltscheme at pnkfx.org)
Date: Thu Jan 22 00:28:09 EST 2004

Guillaume-

This isn't exactly what you asked for, but this is how I do it when I 
want the "open value" behavior.

   (define-syntax define-struct*
     (syntax-rules ()
       [(define-struct* ARGS ...)
        (define-struct ARGS ... (make-inspector))]))

   (define (open-struct->list s)
     (let f ((s s))
       (cond [(struct? s)
              (map f (vector->list (struct->vector s)))]
             [else s])))

Note that you have to wrap structural values with a call to 
"open-struct->list" to pull out the underlying data for printing.  But 
I think things like equal? work without calling "open-struct->list"

Also, as I discovered today, this approach will not work for code that 
has macros that expand into define-struct definitions.  You have to do 
something more clever for that; if you need that, let us know and  
Richard and Ryan will post the solution that they came up with to the 
list.

-Felix

On Jan 21, 2004, at 10:32 PM, Guillaume Marceau wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
>
> The following code does not behaves the same under drscheme and 
> mzscheme
> with respect to inspectors:
>
>    (define-struct loc (x y) (make-inspector))
>    (display (format "~a~n" (make-loc 4 5)))
>
> Under mzscheme, it prints the opaque value:
>     #<struct:loc>
>
> Under drscheme, it prints the open value:
>     #(struct:loc 4 5)
>
> I'm not sure I understand why there is a difference.
> Is it possible to get the open value behavior under mzscheme?
>
> -- 
> "The thing I remember most about America is that it's silly.
>  That can be quite a relief at times."  -- Thom Yorke, Radiohead
>
> - Guillaume
>

----
"A computer lets you make more mistakes faster then any
other invention with the possible exceptions of handguns
and Tequila"  -Mitch Ratcliffe



Posted on the users mailing list.