Next: , Previous: , Up: Structures   [Contents][Index]


6.6.18.3 Vtable Contents

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.

Scheme Variable: vtable-index-layout
C Macro: scm_vtable_index_layout

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.

Scheme Variable: vtable-index-printer
C Macro: scm_vtable_index_printer

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.

Scheme Procedure: struct-vtable-name vtable
Scheme Procedure: set-struct-vtable-name! vtable name
C Function: scm_struct_vtable_name (vtable)
C Function: scm_set_struct_vtable_name_x (vtable, name)

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: , Previous: , Up: Structures   [Contents][Index]