I have a situation where I defined a couple of module-level instance variables using the 'private' scope identifier. I require to do this because these variables will be used in several functions within the module. Also, some of these variables are 'lists' or 'sets'. I realized that values of these variables persist between repeated calls to a certain function within the module. This is as expected.
I am also creating a test where I call one of the functions repeatedly. I would prefer to have a fresh copy of the instance variables (just like with instance members in Java). I can't seem to do so. If I try to nullify the content of the list/set, I get into trouble as follows:
module foo::bar
private set[DataType_1] data1;
public void nullifyInstanceVars( )
{
//tried
data1={}
}
//method that gets called repeatedly:
public void repeatCallMe(..)
{
nullifyInstanceVars( );
...
..
//Throws an error like: trying to add an element of type 1 to set[void]
data1 += anElementOfType1
}
So, I modified the nullifyInstanceVars( ) method to have set[DataType1] data1={ }. It doesn't work because I believe that simply creates a new variable scoped only within the function and really doesn't clear the element!
Any help is appreciated...
This really looks like a bug in the Rascal interpreter. I will file a bug report for it.
The work around is to initialize
data1
in the declaration as well:Can you confirm that this solves your problem?