Occam easily extends its process-based model to include procedures. In occam, a procedure is simply a named process that takes formal input parameters. A procedure starts with the keyword PROC, the procedure's name, and a list of arguments. The body of the procedure is terminated with a single colon. For example, a procedure may be used to set a new variable to the maximum of two others (Burns, 1988, p. 86):

    PROC Maximum( INT A, B, INT Max )      
        A > B
          Max := A
          Max := B

Parameters are typically passed by reference, although entering the VAL keyword in the parameter list before the variable name can force pass by value. Calling a procedure is exceptionally easy, as the procedure may be called like any other process.

      INT A, B, Max:                       
        A := 1
        B := 4
        Maximum( A, B, Max )    

As procedures in occam simply represent processes in occam's linear execution space, occam procedures may not be recursive. All procedures may be implemented by the compiler through code substitution and variable renaming.


Occam supports a very limited approach to functions which return a value. To prevent the creation of functions which introduce their own concurrency and potential deadlock danger, occam prohibits functions from creating any side-effects. That is, an occam function may return a value, but it may not change any variables outside of its local scope. Specifically (Burns, 1988):
  1. Only sequential code sequences (SEQ) are permitted; parallel (PAR) constructs are not allowed.
  2. Only single code sequences are permitted. The SEQ constructor may not create an arbitrary number of processes using ALT.
  3. Channel input and output operations are prohibited.
Basically, a function may accept input parameters, perform assignments on temporary variables, and return a single result. Functions are defined with a return type, the FUNCTION keyword, the name of the function, and then a parameter list. The FUNCTION structure must include two statements following the VALOF keyword. The first statement is always executed and may be a SEQ performing the calculations. The second statement must be RESULT describing the value to return to the calling procedure. For example, the following function averages two values (Burns, 1988, p. 100):

      REAL32 FUNCTION average( VAL REAL32 A, B )     
        REAL32 Temp:
            Temp := ( A + B ) / FLOAT 2 
          RESULT Temp

In the case of simple functions, the return value may be calculated without the use of a temporary variable:

      REAL32 FUNCTION average( VAL REAL32 A, B )     
          RESULT ( A + B ) / FLOAT 2

Occam allows such simple single-statement procedures to be expressed using an alternate form omitting the VALOF keyword. Instead, the return value is specified after IS:

      REAL32 FUNCTION average( VAL REAL32 A, B ) IS  
        ( A + B ) / FLOAT 2

Thus, occam's functions and procedures provide flexible but extremely limited modularity.

Next: The KRoC occam compiler
Return to Index