Warning: This is the manual of the legacy Guile 2.2 series. You may want to read the manual of the current stable series instead.
Next: Meta-Vtables, Previous: Structure Basics, Up: Structures [Contents][Index]
A vtable is itself a structure. It has a specific set of fields describing various aspects of its instances: the structures created from a vtable. Some of the fields are internal to Guile, some of them are part of the public interface, and there may be additional fields added on by the user.
Every vtable has a field for the layout of their instances, a field for the procedure used to print its instances, and a field for the name of the vtable itself. Access to the layout and printer is exposed directly via field indexes. Access to the vtable name is exposed via accessor procedures.
The field number of the layout specification in a vtable. The layout
specification is a symbol like pwpw
formed from the fields
string passed to make-vtable
, or created by
make-struct-layout
(see Meta-Vtables).
(define v (make-vtable "pwpw" 0)) (struct-ref v vtable-index-layout) ⇒ pwpw
This field is read-only, since the layout of structures using a vtable cannot be changed.
The field number of the printer function. This field contains #f
if the default print function should be used.
(define (my-print-func struct port) ...) (define v (make-vtable "pwpw" my-print-func)) (struct-ref v vtable-index-printer) ⇒ my-print-func
This field is writable, allowing the print function to be changed dynamically.
Get or set the name of vtable. name is a symbol and is used in the default print function when printing structures created from vtable.
(define v (make-vtable "pw")) (set-struct-vtable-name! v 'my-name) (define s (make-struct v 0)) (display s) -| #<my-name b7ab3ae0:b7ab3730>
Next: Meta-Vtables, Previous: Structure Basics, Up: Structures [Contents][Index]