Title image for OpenSourceApi
Title image for WikiApi
Programming into Science
Science into Programming
Version

Context

Context is an interface used for retrieving and binding values with identifiers, similar to Map, but with the added capacity to retrieve values from higher level contexts if they are not found in the present context. This functionality is a type of cascading map, where values are available at any point below where they are set unless they are overridden by a parameter with the same identifier. Therefore, parameters may be set for whole branches of code, individual actions, or just specific iterations.

The standard use of context is to define the environment for the code execution. This includes things such as implementations of interfaces, configuration settings, and access to external connections.

Structure

The structure of context is specific to the execution of code and, therefore, has some differences from the structure of a normal cascading map. One difference is that there are two distinct relationships with higher level contexts. The first is the parent context, based on the location of the code, where parameters are available only in the branch where they are set. The second is the precursor context, based on the call tree, where parameters are available anywhere deeper than the function where they are set.

Creation

The creation of contexts most frequently occurs when calling between branches or Resources. When created in this way, the system creates a pair of contexts to enable separation between parameters set for a specific branch and those set to be available throughout the entire call tree.

Searching

When searching on a context, each of the two higher level contexts is referenced in turn if a value is not found in the present level of context. The diagram below illustrates the search procedure.

Diagram 1: Context search procedure

The diagram displays the search procedure for a context that has just been called from a separate branch, represented by the arrow. The current context (yellow) has two types of higher level contexts, those that are parent contexts (green) and those that are precursor contexts (blue). The numbers display the order of the search with all parent contexts being searched before the precursor contexts. Note that the uncolored contexts are not included in the search.