[plt-scheme] idioms for inspectors?

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Jun 18 18:21:32 EDT 2003

One way:

  ;; in file "test-code.ss"
  (module test-code mzscheme
    (define function-to-test
      (parameterize ([current-inspector (make-inspsector)])
        (dynamic-require "my-code.ss" 'function-to-test)))
    .. test function-to-test ...)

  ;; in same dir as above "my-code.ss"
  (module my-code mzscheme
    (provide function-to-test)
    (define ...))

But I wouldn't bother. inspectors aren't really designed for that, I
don't think.

In principle, if you have the struct identifier itself, you should have
enough to make equal? work (nevermind that equal? itself isn't
implemented to take advantage of that).

As an example, the make-->vector macro takes the name of a structure a
produces a function that turns the struct instances into vectors.
Probably this is enough for your test suite (or, perhaps you could just
write a similar macro that did equality testing).

  (define-syntax (make-->vector stx)
    (syntax-case stx ()
      [(_ name) ; a struct type name
       (identifier? (syntax name))
       (let ([info (syntax-local-value (syntax name))])
         (if (struct-declaration-info? info)
             (with-syntax ([(accessor ...)
                             (filter identifier? (list-ref info 3)))])
                (lambda (s)
                  (vector (accessor s) ...))))
              "not a declared structure type name"
              (syntax name))))]))

I don't think that we've really gotten the best design yet, as far as
inspectors go.


At Wed, 18 Jun 2003 13:02:40 -0400, "Richard C. Cobbe" wrote:
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 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?
> Thanks,
> Richard

Posted on the users mailing list.