All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class epp.Dynamic

java.lang.Object
   |
   +----epp.Dynamic

public abstract class Dynamic
extends Object
The Dynamic class provides the same mechanism as the lisp dynamic variable.

Dynamic variables are similar to global variables except that their scope are dynamic.

The bind method saves old values to the stack and then modifies the actual value. The unbind method retrieves values from the stack and restores the original values of the variables last bound.

Subclasses of type Object are the only values you can assign to a dynamic variable. Dynamic variables are initially in an unbound state. If you try to set/get a value when in this state, an UnboundDynamicVariableAccessException will be thrown.

You would frequently want to wrap an int type with an Integer class and assign it to a dynamic variable. The methods bindInt, getInt, and setInt are provided for this purpose. If you use these methods, arguments and return values will be wrapped/unwrapped automatically with the Integer class. (Future versions will save int types and Object types in separate locations.)

Example
-------
void foo(){
  ...;
  Dynamic.bind(:sym1, val1);
  Dynamic.bind(:sym2, val2);
  try {				// Do try immediatly after bind.
    ...;
    bar();
    ...;
    return;
  } finally {			// Do unbind the same number of times as you did bind.
    Dynamic.unbind();
    Dynamic.unbind();
  }
}
void bar(){
  Object val = Dynamic.get(:sym1);
  Dynamic.set(:sym2, val);
}

See Also:
UnboundDynamicVariableAccessException

Constructor Index

 o Dynamic()

Method Index

 o bind(Symbol, Object)
Binds the dynamic variable var to value val.
 o bindInt(Symbol, int)
Binds the dynamic variable var to value new Integer(val).
 o get(Symbol)
Retrieves the current value of the dynamic variable var.
 o getInt(Symbol)
Retrieves the value of type int from the dynamic variable var.
 o set(Symbol, Object)
Changes the value of the dynamic variable var to val.
 o setInt(Symbol, int)
Changes the value of the dynamic variable var to new Integer(val).
 o unbind()
Restores the original value of the dynamic variable saved by the bind method.

Constructors

 o Dynamic
 public Dynamic()

Methods

 o bind
 public static void bind(Symbol var,
                         Object val)
Binds the dynamic variable var to value val. The old value of the dynamic variable var is saved in another place.

 o bindInt
 public static void bindInt(Symbol var,
                            int val)
Binds the dynamic variable var to value new Integer(val). The old value of the dynamic variable var is saved in another place.

 o unbind
 public static void unbind()
Restores the original value of the dynamic variable saved by the bind method.

 o get
 public static Object get(Symbol var)
Retrieves the current value of the dynamic variable var.

 o getInt
 public static int getInt(Symbol var)
Retrieves the value of type int from the dynamic variable var. To be precise, the method does the same thing as the following.
   ((Integer)Dynamic.get(var)).intValue()

 o set
 public static void set(Symbol var,
                        Object val)
Changes the value of the dynamic variable var to val. Unlike the bind method, the old value is not saved.

 o setInt
 public static void setInt(Symbol var,
                           int val)
Changes the value of the dynamic variable var to new Integer(val). Unlike the bindInt method, the old value is not saved.


All Packages  Class Hierarchy  This Package  Previous  Next  Index