<div dir="ltr">Super!  Thank you.<div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 29, 2015 at 7:51 AM, Matthew Flatt <span dir="ltr"><<a href="mailto:mflatt@cs.utah.edu" target="_blank">mflatt@cs.utah.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">At Wed, 28 Jan 2015 16:21:51 -0700, Byron Davies wrote:<br>
> Your code, commented:<br>
><br>
> (define orig-i (current-inspector))  ; saves the original inspector<br>
> (define sub-i (make-inspector orig-i))  ;make a new inspector whose parent<br>
> is the original inspector<br>
><br>
> (current-inspector sub-i)  ;makes the new inspector the current inspector<br>
> (struct a (x))  ; creates a structure using the new inspector as the<br>
> default inspector<br>
> (define v (a 1))  ; creates an instance of the new structure<br>
> (current-inspector orig-i) ;reverts the inspector to the original (the<br>
> parent of the new inspector)<br>
><br>
> I see how this works, but I'm a little confused about why it works.  I see<br>
> that the new inspector is a child of the old one, and I read in the<br>
> reference chapter that access is determined not by the inspector in force<br>
> at creation time, but by the parent of that inspector, i.e., the old<br>
> inspector. I can't find any description of the "power" of an inspector,<br>
> except that the parent is more powerful.<br>
><br>
> Are there degrees of power? Or if you have access to the parent do you have<br>
> all the power you can have?<br>
<br>
There are degrees only in that you can have a hierarchy of inspectors.<br>
Inspector I is more powerful than inspector J if I is an ancestor of J.<br>
<br>
I'll try to improve the docs, such as replacing "more powerful than"<br>
with "an ancestor of".<br>
<br>
> I see that the inspector gives you access to<br>
> the data in a structure instance, but does it also give you access to<br>
> meta-data, so that I know that the name of the first field in struct a is x?<br>
<br>
You get access to all the metadata.<br>
<br>
It turns out that fields currently have only positions, not names, but<br>
that choice was not a good one. We plan to add support for field names<br>
in the near future, in which case the information will be accessible<br>
through an inspector.<br>
<br>
> I also don't understand how the root inspector works.  I have found that<br>
> setting (current-inspector root-inspector) delivers endless left parens for<br>
> the (a 1) example, presumably because the display function recursively<br>
> tries to inspect the components of the struct, all the way down.<br>
<br>
That's a problem in the pretty printer. The pretty printer's<br>
implementation includes<br>
<br>
 (cond<br>
   ....<br>
   [(struct? v) ....]<br>
   ....<br>
   [(unquoted? v) ....]<br>
   ....)<br>
<br>
where `unquoted` is an internal structure. By setting the inspector to<br>
the root inspector, a value that satisfies `unquoted?` also satisfies<br>
`struct?`, and so printing doesn't reach the intended case. I'll push a<br>
repair.<br>
<br>
<br>
> Finally, does this also work for classes?<br>
<br>
Yes. Reflective access to information via `object-info` and<br>
`class-info` is controlled by inspectors.<br>
<br>
</blockquote></div><br></div>