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

9.1 Structures

There is, in Bigloo, a new class of objects: structures, which are equivalent to C struct.

bigloo syntax: define-struct name field…

This form defines a structure with name name, which is a symbol, having fields field… which are symbols or lists, each list being composed of a symbol and a default value. This form creates several functions: creator, predicate, accessor and assigner functions. The name of each function is built in the following way:

  • Creator: make-name
  • Predicate: name?
  • Accessor: name-field
  • Assigner: name-field-set!

Function make-name accepts an optional argument. If provided, all the slots of the created structures are filled with it. The creator named name accepts as many arguments as the number of slots of the structure. This function allocates a structure and fills each of its slots with its corresponding argument.

If a structure is created using make-name and no initialization value is provided, the slot default values (when provided) are used to initialize the new structure. For instance, the execution of the program:

(define-struct pt1 a b)
(define-struct pt2 (h 4) (g 6))

(make-pt1)
   ⇒ #{PT1 () ()}
(make-pt1 5)
   ⇒ #{PT1 5 5}
(make-pt2)
   ⇒ #{PT2 4 6}
(make-pt2 5)
   ⇒ #{PT2 5 5}
bigloo procedure: struct? obj

Returns #t if and only if obj is a structure.


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

This document was generated on October 23, 2011 using texi2html 5.0.

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