Objects

Defining a structure

Besides function definitions, which themselves consist of statements, another top-level syntax element that is allowed in the language are the userdefined structures. Those can include a number of membervariables (also referred to as fields) and also functions, a constructor and a destructor.

Here is an example of a user defined structure for rational numbers, represented nominator and denominator pairs.
struct rational
{
  /* a rational is nominator/denominator */
  int nom, denom;

  /* yes, a constructor */
  rational (int nom, int denom)
  {
    this.nom = nom;
    this.denom = denom;
    this.normalize (); 
  }
   
  /* and a destructor */
  ~rational ()
  {
    /* keeping it empty, but its invoked anyhow */
  }
   
  /* and a member function */
  rational print ()
  {
    pri (this.nom); prs ("/"); pri (this.denom);
    return this;
  }
   
  /* set the rational to a value */
  void set (int nom, int denom)
  {
    this.nom = nom;
    this.denom = denom;
  }
   
  /* normalize a rational number */
  void normalize ()
  {
    int div;
    div = gcd (this.nom, this.denom);
    this.nom /= div;
    this.denom /= div;
  }  
}    

Constructor and destructor semantics

Constructors are invoked after the allocation of the memory. Destructors are invoked before the free'ing of memory. Neither constructors nor destructors are allowed or needed to allocate or free their own storage. Allocation and free'ing of nested objects is allowed though. Accessing of the structure's field is possible by means of the implicitly declared "this" pointer.

Member functions

Similiar to constructors and destructors, member functions do possess an implicitly declared pointer of the structure they belong to which is called "this". This pointer allows the modification and inspection of one particular instance of the user defined structure.