[plt-scheme] Default (define-struct ...) behavior

From: Richard Cobbe (cobbe at ccs.neu.edu)
Date: Thu Sep 20 20:58:56 EDT 2007

On Thu, Sep 20, 2007 at 05:16:53PM -0400, Matt Jadud wrote:
> OK. I'll buy that.
> It came up mostly because some of my students are experimenting with
> full Scheme, and they're accustomed to the constructor syntax. With an
> inspector, you get a distinct printed representation that still lets
> them see what the contents of the structure they created/are testing
> in the interactions window. If, of course, one says
> "(make-inspector)", which is a rather opaque.

There are a couple of options that aren't any less opaque but are at least
less typing.

In recent versions of PLT Scheme, instead of typing

    (define-struct posn (x y) (make-inspector))

you can type

    (define-struct posn (x y) #f)

to get the same effect.

Alternatively, if you have a lot of structures to define and you want them
all to be visible, then check out the inspector.plt planet package by
dherman.  With that, you can write

      (define-struct posn (x y))

and all of the structures that you define inside `with-public-inspector'
are visible by the current inspector.  This macro also has the advantage
that it even works with macros that expand into `define-struct'---you can't
add #f or (make-inspector) to those.


Posted on the users mailing list.