Statements

Statements form the bodies of classes. Within the sequence of statements forming a class definition, there may (and indeed, typically will) also occur definitions of actions and requests, which themselves have statement sequences as their bodies.

Statements will typically have side-effects, affecting the state of objects or the external world. This implies that the order of statements within a sequence is important.

Expressions within a statement sequence may furthermore refer to the state variables of the enclosing object. The values thus obtained are the current state values at the time of executing each statement. In particular, a function referencing to a state variable in its body is referring to the value of that variable at the point of function definition, not the possible values the variable might have when the function is called.

The available statement forms are:

The forms of statements up to now are the only forms that may occur in the statement sequence of a class; creating an object may only involve initiating the state, creating other objects and returning the proper interface. The remaining forms occur only within methods and procedures.

We finish with a simple example.
struct Counter where
  inc   :: Action
  read  :: Request Int
  reset :: Action

counter = class
  s := 0
  inc = action
    s := s+1
  read = request
    result s
  reset = action
    s := 0
  result Counter {..}