www.delorie.com/gnu/docs/guile/guile_234.html   search  
Buy GNU books!

Guile Reference Manual

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

22.5.3 Structure Basics

This section describes the basic procedures for creating and accessing structures.

Scheme Procedure: make-struct vtable tail_array_size . init
C Function: scm_make_struct (vtable, tail_array_size, init)
Create a new structure.

type must be a vtable structure (see section 22.5.4 Vtables).

tail-elts must be a non-negative integer. If the layout specification indicated by type includes a tail-array, this is the number of elements allocated to that array.

The init1, ... are optional arguments describing how successive fields of the structure should be initialized. Only fields with protection 'r' or 'w' can be initialized, except for fields of type 's', which are automatically initialized to point to the new structure itself; fields with protection 'o' can not be initialized by Scheme programs.

If fewer optional arguments than initializable fields are supplied, fields of type 'p' get default value #f while fields of type 'u' are initialized to 0.

Structs are currently the basic representation for record-like data structures in Guile. The plan is to eventually replace them with a new representation which will at the same time be easier to use and more powerful.

For more information, see the documentation for make-vtable-vtable.

Scheme Procedure: struct? x
C Function: scm_struct_p (x)
Return #t iff x is a structure object, else #f.

Scheme Procedure: struct-ref handle pos
Scheme Procedure: struct-set! struct n value
C Function: scm_struct_ref (handle, pos)
C Function: scm_struct_set_x (struct, n, value)
Access (or modify) the nth field of struct.

If the field is of type 'p', then it can be set to an arbitrary value.

If the field is of type 'u', then it can only be set to a non-negative integer value small enough to fit in one machine word.

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

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003