Go to the first, previous, next, last section, table of contents.


Vtables are structures that are used to represent structure types. Each vtable contains a layout specification in field vtable-index-layout -- instances of the type are laid out according to that specification. Vtables contain additional fields which are used only internally to libguile. The variable vtable-offset-user is bound to a field number. Vtable fields at that position or greater are user definable.

primitive: struct-vtable struct
Return the vtable structure that describes the type of struct.

primitive: struct-vtable? obj
Return #t iff obj is a vtable structure.

If you have a vtable structure, V, you can create an instance of the type it describes by using (make-struct V ...). But where does V itself come from? One possibility is that V is an instance of a user-defined vtable type, V', so that V is created by using (make-struct V' ...). Another possibility is that V is an instance of the type it itself describes. Vtable structures of the second sort are created by this procedure:

primitive: make-vtable-vtable new-fields tail-size . inits
Return a new, self-describing vtable structure.

new-fields is a layout specification describing fields of the resulting structure beginning at the position bound to vtable-offset-user.

tail-size specifies the size of the tail-array (if any) of this vtable.

inits initializes the fields of the vtable. Minimally, one initializer must be provided: the layout specification for instances of the type this vtable will describe. If a second initializer is provided, it will be interpreted as a print call-back function.

;;; loading ,a...
(define x
  (make-vtable-vtable (make-struct-layout (quote pw))

(struct? x)
=> #t
(struct-vtable? x)
=> #t
(eq? x (struct-vtable x))
=> #t
(struct-ref x vtable-offset-user)
=> foo
(struct-ref x 0)
=> pruosrpwpw

(define y
  (make-struct x
               (make-struct-layout (quote pwpwpw))

(struct? y)
=> #t
(struct-vtable? y)
=> #t
(eq? x y)
=> ()
(eq? x (struct-vtable y))
=> #t
(struct-ref y 0)
=> pwpwpw
(struct-ref y vtable-offset-user)
=> bar

(define z (make-struct y 0 'a 'b 'c))

(struct? z)
=> #t
(struct-vtable? z)
=> ()
(eq? y (struct-vtable z))
=> #t
(map (lambda (n) (struct-ref z n)) '(0 1 2))
=> (a b c)

Go to the first, previous, next, last section, table of contents.