[plt-scheme] idioms for inspectors?

From: Richard C. Cobbe (cobbe at ccs.neu.edu)
Date: Wed Jun 18 13:02:40 EDT 2003

I have a basic idea of how inspectors work, but I'm not sure about the
standard idioms for using them.

So, here's my situation:

  (module ast mzscheme ...)
  (module parser mzscheme (require ast) ...)

The first module defines and exports a bunch of structures that I use as
the AST for the language I'm working with.  The parser module parses an
s-expression and produces an AST made from these structures.

I'm trying to write test cases for the parser module, which compare the
expected results and the actual results using equal?.  This obviously
requires a sufficiently powerful inspector.

I've achieved this by writing the ast module as follows:

(module ast mzscheme
  (define old-inspector (current-inspector))
  (current-inspector (make-inspector))

  (define-struct program (defns main))
  (define-struct defn (name superclass fields methods))

  (current-inspector old-inspector)

  (provide (struct program (defns main))
           (struct defn (name superclass fields methods))

This obviously works, but it strikes me as overly broad: it grants
access to *everyone*, not just the test cases.  Is there a way I can use
inspectors to restrict this a bit but still make my test cases work?



Posted on the users mailing list.