A vtable is itself a structure, with particular fields that hold information about the structures to be created. These include the fields of those structures, and the print function for them. The variables below allow access to those fields.
Return
#t
if obj is a vtable structure.Note that because vtables are simply structures with a particular layout,
struct-vtable?
can potentially return true on an application structure which merely happens to look like a vtable.
The field number of the layout specification in a vtable. The layout specification is a symbol like
pwpw
formed from the fields string passed tomake-vtable
, or created bymake-struct-layout
(see Vtable Vtables).(define v (make-vtable "pwpw" 0)) (struct-ref v vtable-index-layout) ⇒ pwpwThis field is read-only, since the layout of structures using a vtable cannot be changed.
A self-reference to the vtable, ie. a type
s
field. This is used by C code within Guile and has no use at the Scheme level.
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-funcThis 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>