Skip to main content

Standardizing Access to Global Variables

Conventional systems often maintain global "variables" that can be accessed by modules throughout the system. Such variables are typically manipulated using primitives of the form:

  1. Return the current value of V.
  2. Replace the current contents of V with a new value.

These primitives are either provided as language constructs or implemented by specialized procedures. The former approach encourages uniform treatment of all variables within the system.

Those distributed systems that maintain remotely-accessible variables must also select a strategy for implementing the required access primitives. While such primitives can, of course, be implemented as specialized applications procedures, adding to the Protocol the following new system procedures insures a uniform run-time access mechanism:

RDVARIABLE (pkh,  variable -> value)
INDEX CHARSTR any
WRVARIABLE (pkh, variable, value)
INDEX CHARSTR any

These procedures effectively define variables as named data objects modeled from PCP data types, and suggest that they be clustered in packages with related procedures. The system procedures return and specify, respectively, the VALUE of the VARIABLE whose name and package handle PKH are specified.

These new procedures enable the environment to make available its applications program, primitives that have calling sequences similar to those of the corresponding system procedures but which accept the process handle of the target process as an additional argument. These primitives provide a basis upon which a suitably modified compiler can reestablish the compile-time uniformity that characterizes the manipulation of variables in conventional programming environments. Their implementation requires only that the local environment identify the remote process from its internal tables and invoke RDVARIABLE or WRVARIABLE in that process.

Most variables will restrict the range of data types and values that may be assigned to them; some may even be read-only. But because they are modeled using PCP data types, their values can, in principle, be arbitrarily complex (for example, a LIST of LISTS) and the programmer may sometimes wish to manipulate only a single element of the variable (or, if the element is itself a LIST, just one of its elements; and so on, to arbitrary depth).

Adding the following argument to their calling sequences extends the system procedures proposed above to optionally manipulate a single element of a variable's composite value:

substructure
(LISTofINDEXs)

At successive levels of the value's tree structure, the INDEX of the desired element is identified; the resulting list of indices identifies the SUBSTRUCTURE whose value is to be returned or replaced.