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.
If you have a vtable structure,
V, you can create an instance of
the type it describes by using
(make-struct V ...). But where
V itself come from? One possibility is that
V is an
instance of a user-defined vtable type,
V', so that
created by using
(make-struct V' ...). Another possibility is
V is an instance of the type it itself describes. Vtable
structures of the second sort are created by this procedure:
new-fields is a layout specification describing fields
of the resulting structure beginning at the position bound to
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)) 0 'foo)) (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 0 (make-struct-layout (quote pwpwpw)) 'bar)) (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.