[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: print-struct?



Quoting Doug Orleans:
> Is this a bug, or does print-struct not work like I think it should?
> [...]
> Shouldn't it print the field values with print-struct turned on?

It's not a bug, but the documentation for `print-struct' doesn't
provide enough information for v200.

Short answer:

 (define-struct foo (bar baz) (make-inspector))

creates a transparent `foo' structure.

Long answer:

Structs are now used for values in the DrScheme implementation that
must be protected from malicious code, even to the point of preventing
inspection via printing.

So MzScheme provides inspectors for controlling access to struct
fields. When a struct type is created, it becomes protected by the
current inspector (as determined by the `current-inspector' parameter).
Printing can expose the content of a struct only if the inspector at
the time of printing is a supervisor of the inspector that protects the
struct's type.

The optional last expression for `define-struct' selects a protecting
inspector; `(make-inspector)' creates a new inspector under the current
one.

Matthew