14.9 Structure Inspectors (original) (raw)

14.9 Structure Inspectors🔗

An inspector provides access to structure fields and structure type information without the normal field accessors and mutators. (Inspectors are also used to control access to module bindings; see Code Inspectors.) Inspectors are primarily intended for use by debuggers.

When a structure type is created, an inspector can be supplied. The given inspector is not the one that will control the new structure type; instead, the given inspector’s parent will control the type. By using the parent of the given inspector, the structure type remains opaque to “peer” code that cannot access the parent inspector.

The current-inspector parameter determines a default inspector argument for new structure types. An alternate inspector can be provided though the #:inspector option of thestruct form (see Defining Structure Types: struct), or through an optional inspector argument tomake-struct-type.

Returns #t ifv is an inspector, #f otherwise.

(make-inspector [inspector]) → inspector?
inspector : inspector? = (current-inspector)

Returns a new inspector that is a subinspector ofinspector. Any structure type controlled by the new inspector is also controlled by its ancestor inspectors, but no other inspectors.

(make-sibling-inspector [inspector]) → inspector?
inspector : inspector? = (current-inspector)

Returns a new inspector that is a subinspector of the same inspector as inspector. That is, inspector and the result inspector control mutually disjoint sets of structure types.

(inspector-superior? inspector maybe-subinspector) → boolean?
inspector : inspector?
maybe-subinspector : inspector?

Returns #t if inspector is an ancestor ofmaybe-subinspector (and not equal tomaybe-subinspector), #f otherwise.

Added in version 6.5.0.6 of package base.

A parameter that determines the default inspector for newly created structure types.

Returns two values:

Returns eight values that provide information about the structure type descriptor struct-type, assuming that the type is controlled by the current inspector:

If the type for struct-type is not controlled by the current inspector, the exn:fail:contract exception is raised.

Reports whether struct-type has the prop:sealedstructure type property.

Added in version 8.0.0.7 of package base.

Reports whether struct-type has the prop:authenticstructure type property.

Added in version 8.0.0.7 of package base.

Returns a constructor procedure to create instances of the type for struct-type. If constructor-name is not #f, it is used as the name of the generated constructor procedure. If the type for struct-type is not controlled by the current inspector, theexn:fail:contract exception is raised.

Returns a predicate procedure to recognize instances of the type for struct-type. If the type for struct-typeis not controlled by the current inspector, theexn:fail:contract exception is raised.

If a structure’s type implements the prop:object-name property, and the value of the prop:object-name property is an integer, then the corresponding field of the structure is the name of the structure. Otherwise, the property value must be a procedure, which is called with the structure as argument, and the result is the name of the structure. If a structure is a procedure as implemented by one of its fields (i.e., the prop:procedure property value for the structure’s type is an integer), then its name is the implementing procedure’s name. Otherwise, its name matches the name of the structure type that it instantiates.

The name (if any) of a procedure is a symbol, unless the procedure is also a structure whose type has the prop:object-nameproperty, in which case prop:object-name takes precedence. The procedure-rename function creates a procedure with a specific name.

The name of a regexp value is a string or byte string. Passing the string or byte string to regexp, byte-regexp,pregexp, or byte-pregexp (depending on the kind of regexp whose name was extracted) produces a value that matches the same inputs.

The name of a port can be any value, but many tools use a path or string name as the port’s for (to report source locations, for example).

The name of a logger is either a symbol or #f.

The name of a prompt tag is either the optional symbol given to make-continuation-prompt-tag or #f.

Changed in version 7.9.0.13 of package base: Recognize the name of continuation prompt tags.

A structure type property that allows structure types to customize the result of object-name applied to their instances. The property value can be any of the following:

Added in version 6.2 of package base.