OEP

120

Title

DEFINED dynamic mobile operator support

Summary

Add a DEFINED operator to indicate whether a mobile is currently defined.

Owner

Fred Barnes <F.R.M.Barnes@kent.ac.uk>

Status

Accepted

Date-Accepted

2003-03-20

Keywords

language mobiles defined

For the majority of programming languages, once defined, a variable stays that way -- there is no clear way to undefine variables in most languages (with some exceptions, such as assigning from a function whose result is undefined). In occam, ordinary variables are considered undefined until assignment or input to. Once defined, they stay that way. Mobile variables, however, can transition between undefined and defined, based on the program logic (there is also other definedness states -- partially defined and possibly defined amongst them).

At some points in a program, it may be unknown (in the program logic) whether a particular variable is defined or undefined. For example, consider a mobile channel-end -- it may or may not be connected to a server. Or a dynamic mobile array -- it may either contain zero elements (undefined) or some elements (defined), separate from the definedness states of those elements.

The "DEFINED" operator provides a way of testing this at run-time, with subtle effects on the undefinedness checker. For example, the following code fragment is valid:

CHAN TYPE FOO
  MOBILE RECORD
    CHAN INT c?:
:

FOO! f.c:
SEQ
  IF
    DEFINED f.c
      f.c[c] ! 42
    TRUE
      FOO? f.s:
      SEQ
        f.c, f.s := MOBILE FOO
        FORK server (f.s)
        f.c[c] ! 42

Attempts to use the DEFINED operator with non-dynamic mobiles (i.e. static mobiles and ordinary variables) results in a compiler error. This may be modified in the future to work with other types.

OEP/120 (last edited 2007-09-27 00:30:57 by ats1)