manpagez: man pages & more
info guile
Home | html | info | man
[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6.7.9.3 Vtable Contents

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.

Scheme Procedure: struct-vtable? obj
C Function: scm_struct_vtable_p (obj)

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.

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 section Vtable 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-vtable
C Macro: scm_vtable_index_vtable

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.

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>
Scheme Procedure: struct-vtable-tag vtable
C Function: scm_struct_vtable_tag (vtable)

Return the tag of the given vtable.


[ << ] [ < ] [ Up ] [ > ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on February 3, 2012 using texi2html 5.0.

© manpagez.com 2000-2024
Individual documents may contain additional copyright information.