[plt-scheme] Create new inspector hierarchies?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sat Apr 7 07:46:45 EDT 2007

At Sat, 07 Apr 2007 03:14:40 -0700, Derick Eddington wrote:
> I'd like to be able to selectively delegate the authority to inspect
> structs.

I agree that inspectors don't currently do what you want. There's a
kind of off-by-one effect in requiring the parent of an inspector to
actually inspect. If I had it to do over, I'd split out the two parts
of an inspector --- "owns" versus "can inspect" -- to avoid this
effect. As it is, an operator to create a sibling of an inspector may
be a sensible addition, and I think it would solve your problem.


Meanwhile, if you're selecting at the granularity of struct
definitions, I think a struct-type property should be able to
accomplish the goal.

  (define-values (prop:view view? view-data) 
    (make-struct-type-property 
     'view 
     (lambda (val data)
       ;; Take advantage of the `struct-type-info' data that is
       ;; provided to the guard: use it directly as the property value.
       data)))

  (require (lib "struct.ss"))

  (define-struct/properties a (b c)
    ([prop:view 'ignored]))

  (view-data (make-a 1 2)) 
  ; => essentially the same information as composing
  ;    `struct-type-info' and `struct-info'

Create a different `view' property for each different inspection
domain. You'd want to wrap up the pattern into something more abstract
and convenient, but that's the basic idea.

One nice thing about this approach is that it doesn't inherently rely
on reflection if less is needed. Instead of replacing 'ignored with the
full reflective information that happens to be passed to a guard, you
could attach just the necessary information with the property.

Matthew



Posted on the users mailing list.