Structures

Structures are vector-like objects for which none of the standard Scheme type predicates test true. They are therefore suitable implementation vehicles for new and experimental data types.

There are no structure-length, structure-ref, or structure-set! procedures. Instead, use the vector-like-length, vector-like-ref, and vector-like-set procedures.

Procedure make-structure

(make-structure length) => structure

Returns a structure of the specified length.

Procedure structure?

(structure? object) => boolean

Returns #t if object is a structure, and #f otherwise.

Parameter structure-comparator

The value of this parameter is a procedure of two arguments: the structures to be compared. The default behavior is to compare the structures element-by-element using equal? and return #t if they agree at all fields.

The structure comparator may be called by equal? to compare two structures for equality.

Parameter structure-printer

The value of this parameter is a procedure of three arguments: a structure, an output port, and a boolean which is #t if the printer must quote its output, as for write.

A typical use of structure-printer is to retrieve the current structure printer procedure and install a new procedure that checks its argument to see if it's a structure of a particular type; if it is, then a custom printer is invoked, otherwise the old printer is invoked. For example:

     (define (install-structure-printer mystruct? printer)
       (let ((old (structure-printer)))
         (structure-printer (lambda (obj port quote?)
                              (if (mystruct? obj)
                                  (printer obj port quote?)
                                  (old obj port quote?))))))


$Id: structures.html,v 1.4 2000/09/12 02:46:46 lth Exp $
larceny@ccs.neu.edu