/racket-5-0-2-bin-i386-osx-mac-dmg/collects/scribblings/reference/struct-inspectors.scrbl

http://github.com/smorin/f4f.arc · Racket · 169 lines · 121 code · 48 blank · 0 comment · 3 complexity · 86daf567d8e080f296a1c0a8af0ddcf1 MD5 · raw file

  1. #lang scribble/doc
  2. @(require "mz.ss")
  3. @title[#:tag "inspectors"]{Structure Inspectors}
  4. An @deftech{inspector} provides access to structure fields and
  5. structure type information without the normal field accessors and
  6. mutators. (Inspectors are also used to control access to module
  7. bindings; see @secref["modprotect"].) Inspectors are primarily
  8. intended for use by debuggers.
  9. When a structure type is created, an inspector can be supplied. The
  10. given inspector is not the one that will control the new structure
  11. type; instead, the given inspector's parent will control the type. By
  12. using the parent of the given inspector, the structure type remains
  13. opaque to ``peer'' code that cannot access the parent inspector.
  14. The @scheme[current-inspector] @tech{parameter} determines a default
  15. inspector argument for new structure types. An alternate inspector can
  16. be provided though the @scheme[#:inspector] option of the
  17. @scheme[define-struct] form (see @secref["define-struct"]), or
  18. through an optional @scheme[inspector] argument to
  19. @scheme[make-struct-type].
  20. @defproc[(inspector? [v any/c]) boolean?]{Returns @scheme[#t] if
  21. @scheme[v] is an inspector, @scheme[#f] otherwise.}
  22. @defproc[(make-inspector [inspector inspector? (current-inspector)])
  23. inspector?]{
  24. Returns a new inspector that is a subinspector of
  25. @scheme[inspector]. Any structure type controlled by the new inspector
  26. is also controlled by its ancestor inspectors, but no other
  27. inspectors.}
  28. @defproc[(make-sibling-inspector [inspector inspector? (current-inspector)])
  29. inspector?]{
  30. Returns a new inspector that is a subinspector of the same inspector
  31. as @scheme[inspector]. That is, @scheme[inspector] and the result
  32. inspector control mutually disjoint sets of structure types.}
  33. @defparam[current-inspector insp inspector?]{
  34. A parameter that determines the default inspector for newly created
  35. structure types.}
  36. @defproc[(struct-info [v any/c])
  37. (values (or/c struct-type? #f)
  38. boolean?)]{
  39. Returns two values:
  40. @itemize[
  41. @item{@scheme[_struct-type]: a structure type descriptor or @scheme[#f];
  42. the result is a structure type descriptor of the most specific type
  43. for which @scheme[v] is an instance, and for which the current
  44. inspector has control, or the result is @scheme[#f] if the current
  45. inspector does not control any structure type for which the
  46. @scheme[struct] is an instance.}
  47. @item{@scheme[_skipped?]: @scheme[#f] if the first result corresponds to
  48. the most specific structure type of @scheme[v], @scheme[#t] otherwise.}
  49. ]}
  50. @defproc[(struct-type-info [struct-type struct-type?])
  51. (values symbol?
  52. exact-nonnegative-integer?
  53. exact-nonnegative-integer?
  54. struct-accessor-procedure?
  55. struct-mutator-procedure?
  56. (listof exact-nonnegative-integer?)
  57. (or/c struct-type? #f)
  58. boolean?)]{
  59. Returns eight values that provide information about the structure type
  60. descriptor @scheme[struct-type], assuming that the type is controlled
  61. by the current inspector:
  62. @itemize[
  63. @item{@scheme[_name]: the structure type's name as a symbol;}
  64. @item{@scheme[_init-field-cnt]: the number of fields defined by the
  65. structure type provided to the constructor procedure (not counting
  66. fields created by its ancestor types);}
  67. @item{@scheme[_auto-field-cnt]: the number of fields defined by the
  68. structure type without a counterpart in the constructor procedure
  69. (not counting fields created by its ancestor types);}
  70. @item{@scheme[_accessor-proc]: an accessor procedure for the structure
  71. type, like the one returned by @scheme[make-struct-type];}
  72. @item{@scheme[_mutator-proc]: a mutator procedure for the structure
  73. type, like the one returned by @scheme[make-struct-type];}
  74. @item{@scheme[_immutable-k-list]: an immutable list of exact
  75. non-negative integers that correspond to immutable fields for the
  76. structure type;}
  77. @item{@scheme[_super-type]: a structure type descriptor for the
  78. most specific ancestor of the type that is controlled by the
  79. current inspector, or @scheme[#f] if no ancestor is controlled by
  80. the current inspector;}
  81. @item{@scheme[_skipped?]: @scheme[#f] if the seventh result is the
  82. most specific ancestor type or if the type has no supertype,
  83. @scheme[#t] otherwise.}
  84. ]
  85. If the type for @scheme[struct-type] is not controlled by the current inspector,
  86. the @exnraise[exn:fail:contract].}
  87. @defproc[(struct-type-make-constructor [struct-type struct-type?])
  88. struct-constructor-procedure?]{
  89. Returns a @tech{constructor} procedure to create instances of the type
  90. for @scheme[struct-type]. If the type for @scheme[struct-type] is not
  91. controlled by the current inspector, the
  92. @exnraise[exn:fail:contract].}
  93. @defproc[(struct-type-make-predicate [struct-type any/c]) any]{
  94. Returns a @tech{predicate} procedure to recognize instances of the
  95. type for @scheme[struct-type]. If the type for @scheme[struct-type]
  96. is not controlled by the current inspector, the
  97. @exnraise[exn:fail:contract].}
  98. @defproc[(object-name [v any/c]) any]{
  99. Returns a value for the name of @scheme[v] if @scheme[v] has a name,
  100. @scheme[#f] otherwise. The argument @scheme[v] can be any value, but
  101. only (some) procedures, @tech{structures}, @tech{structure types},
  102. @tech{structure type properties}, @tech{regexp values}, and
  103. @tech{ports} have names. See also @secref["infernames"].
  104. The name (if any) of a procedure is always a symbol. The
  105. @scheme[procedure-rename] function creates a procedure with a specific
  106. name.
  107. The name of a @tech{structure}, @tech{structure type}, @tech{structure
  108. type property} is always a symbol. If a @tech{structure} is a
  109. procedure as implemented by one of its fields (i.e., the
  110. @scheme[prop:procedure] property value for the structure's type is an
  111. integer), then its name is the implementing procedure's name;
  112. otherwise, its name matches the name of the @tech{structure type} that
  113. it instantiates.
  114. The name of a @tech{regexp value} is a string or byte string. Passing
  115. the string or byte string to @scheme[regexp], @scheme[byte-regexp],
  116. @scheme[pregexp], or @scheme[byte-pregexp] (depending on the kind of
  117. regexp whose name was extracted) produces a value that matches the
  118. same inputs.
  119. The name of a port can be any value, but many tools use a path or
  120. string name as the port's for (to report source locations, for
  121. example).}