Section 3.4. The Object Inspector A facility for noninteractive inspection is also provided to allow construction of different inspection interfaces. Like the interactive facility, it allows objects to be examined in ways not ordinarily possible. The noninteractive system follows a simple, object-oriented protocol. Ordinary Scheme objects are encapsulated in procedures, or inspector objects, that take symbolic messages and return either information about the encapsulated object or new inspector objects that encapsulate pieces of the object. procedure: (inspect/object object) returns: an inspector object procedure libraries: (scheme) inspect/object is used to turn an ordinary Scheme object into an inspector object. All inspector objects accept the messages type, print, and write. The type message returns a symbolic representation of the type of the object. The print and write messages must be accompanied by a port parameter. They cause a representation of the object to be written to the port, using the Scheme procedures pretty-print and write. All inspector objects except for variable inspector objects accept the message value, which returns the actual object encapsulated in the inspector object. (define x (inspect/object '(1 2 3))) (x 'type) pair (define p (open-output-string)) (x 'write p) (get-output-string p) "(1 2 3)" (x 'length) (proper 3) (define y (x 'car)) (y 'type) simple (y 'value) 1 Procedure inspector objects. Procedure inspector objects contain Scheme procedures. (procedure-object 'type) returns the symbol procedure. (procedure-object 'length) returns the number of free variables. (procedure-object 'ref n) returns an inspector object containing the nth free variable of the procedure. See the description below of variable inspector objects. n must be nonnegative and less than the length of the procedure. (procedure-object 'eval expr) evaluates expr and returns its value. The values of the procedure's free variables are bound within the evaluated expression to identifiers of the form %n, where n is the location number displayed by the inspector. The values of named variables are also bound to their names. (procedure-object 'code) returns an inspector object containing the procedure's code object. See the description below of code inspector objects. Code inspector objects. Code inspector objects contain Chez Scheme code objects. (code-object 'type) returns the symbol code. (code-object 'name) returns a string or #f. The name associated with a code inspector object is the name of the variable to which the procedure was originally bound or assigned. Since the binding of a variable can be changed, this name association may not always be accurate. #f is returned if the inspector cannot determine a name for the procedure. (code-object 'source) returns an inspector object containing the source information attached to the code object or #f if no source information is attached. (code-object 'source-path) attempts to find the pathname of the file containing the source for the lambda expression that produced the code object. If successful, three values are returned to identify the file and position of the application within the file: path, line, and char. Two values, a file name and an absolute character position, are returned if the file name is known but the named file cannot be found. The search may be unsuccessful even if a file by the expected name is found in the path if the file has been modified since the source code was compiled. If no file name is known, no values are returned. The parameter source-directories (Section 12.5) determines the set of directories searched for source files identified by relative path names. (code-object 'free-count) returns the number of free variables in any procedure for which this is the corresponding code. (code-object 'info) returns an inspector object containing the system's internal info structure for the code object. (code-object 'reloc) returns an inspector object containing the system's internal relocation entries for the code object.