next up previous contents index
Next: Top-level Commands Up: Using NESL Previous: Exiting NESL

Variable and Function Redefinition


In most functional languages, when you define a variable with the same name as an existing variable, the new definition shadows the old definition but will not affect any previous references to the old variable. For example:

a = 22;
function foo(b) = a + b;
a = 1.0;
Now a is redefined to be 1.0, but foo would still refer to the value 22.

For the sake of convenience, NESL adds the feature that when you define a variable at the top level and then later redefine it with the same name and type, the system changes all previous references to the variable to the new value (note that function names are variables, so the same is true with function definitions). This allows the user to redefine a variable or function without having to reload everything that depends on it. It is important to realize that previous references to the variable are not redefined if the new value is of a different type, including the redefinition of a function to have a new type (since such a redefinition would lead to type inconsistencies), and that redefining only happens at the top level. The system warns the user when defining a variable with an existing name but a new type. For example:

<Nesl> x=2;
x = 2 : int
<Nesl> x=0.0;
Redefining X with a new type.  Old calls will not be modified.
x = 0.0 : float

Guy Blelloch
Tue Nov 28 18:37:09 EST 1995