FUNCTIONAL


Motivation

We need the ability to identify procedures and methods that do not modify global state, which we call FUNCTIONAL. Event guards are restricted to be FUNCTIONAL, so that the dispatcher can freely optimize their execution.

Definition

An FUNCTIONAL procedure or method is not allowed to call a non-FUNCTIONAL procedure or method. Only the base library routines that do not modify global state are defined as FUNCTIONAL. (We have identified "functional" procedures as FUNCTIONAL as needed.)

A FUNCTIONAL procedure or method has the following additional restriction on its behavior:

Syntax

The keyword PROCEDURE can be preceded by the keyword FUNCTIONAL, both in a procedure type or a procedure definition. A method name in an object type can be preceded by FUNCTIONAL.

Examples

FUNCTIONAL PROCEDURE f(a, b: INTEGER) : INTEGER =
  BEGIN
    RETURN a+b;
  END f;

PROCEDURE g(VAR a: INTEGER) =   (* cannot be FUNCTIONAL *)
  BEGIN
    a := 5;                     (* modifies global state! *)
  END g;


Other SPIN Modula-3 changes

September 19, 1996

whsieh@cs.washington.edu