[plt-scheme] Inspectors in mzscheme
Lo, on Thursday, January 22, Felix Klock's PLT scheme proxy did write:
> Also, as I discovered today, this approach will not work for code that
> has macros that expand into define-struct definitions.
... like the define-tokens form from Scott's parser-tools collection.
> 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.
(define-syntax with-public-inspector
(lambda (stx)
(syntax-case stx ()
[(kw defns ...)
(with-syntax ([old-inspector (datum->syntax-object #'kw (gensym))])
#'(begin
(define old-inspector (current-inspector))
(current-inspector (make-inspector))
defns ...
(current-inspector old-inspector)))])))
Use as follows:
(with-public-inspector
(define-struct loc (x y))
(define-struct foo (bar baz)))
The whole (datum->syntax-object #'kw (gensym)) garbage is necessary when
you define the macro in one module but use it in another; you have to
break hygiene and then patch it back the old-fashioned way, or define
complains. I personally think this is a really awful hack, so if anyone
has any alternatives, please let me know.
Richard