Changing current Context

Subclasses of Element use special preamble in all their non-static methods, except for a few special ones and getters. This is not required for methods which don't have any arguments and return type of Element class (or its subclasses) - @TODO check; fix the following:

Element method( Element arg1, Element arg2... ) {
  if( entered( argX ) ) {
    return up( method( dw( arg1 ), dw( arg2 )... ) );

  // do the actual task...

  • at least one of the methods arguments and/or its return type is Element or its subclass
  • entered( arg ) tests whether the arg entered Context of current this from upper Context
  • dw( arg ) adjusts Element arg to local Context, and applies its mirrors
  • up( returned_result ) unwounds local Context and any mirrors applied by that Context
  • up is used only when the method returns an instance of Element or its subclass
This mechanism is self-assuring. Inductive proof:Top-level Elements - seeds - have their Contexts set by a special method, which follows this contract. Then other Elements have their Context always adapted on one-level differences. An argument is either associated with current Context, or with Context one level higher. If entered( argX ) is true, then the method goes to call itself second time with all arguments adjusted to local Context. In that recursive method invocation it evaluates entered( argX ) to false. This limits depth of up( recursive_call ) section in any method to maximum of one recursive call.

argX in expression entered( argX ) must not be null, because it can't be determined whether null entered from the same of upper Context.

There can be methods other than getters which don't have any Element arguments, but return an Element. These can't employ this mechanism. Their returned Element must be adjusted in place where they are called. If possible, provide External and Internal version of the method. In common cases, External method calls Internal one, and then unwounds the result using up().

An alternative to function header - automated per-thread Context. It would trail method call stack in the way describe above. Its features

  • Context is controlled by code flow. Calling and returning from a component adjusts all references (method parameters) to the current Context.
  • same limits as those of net.sf.reuse package
  • it would be tied to specific platforms/languages and could depend on compiler settings

Elements, static (global) variables and non-Element containers

Elements may be freely stored as normal objects. They can be in static variables, collections and objects which don't support Elements. However, when retrieved from there, they may be not compatible with current Context.

Static Elements are ordinarily used for seeds only. Seeds use top-level "empty" Context. Before used, they are adapted to local Context using a special method. Logo Copyright (c) 2005, 2006, 2007 Peter Kehl