Alpha icon indicating copy to clipboard operation
Alpha copied to clipboard

Atoms (and maybe also rules) should be immutable

Open rtaupe opened this issue 6 years ago • 2 comments

Currently, instances of classes Atom, Rule and NonGroundRule are mutable. This can lead to problems, at least in the following known case:

The final boolean field BasicAtom.ground is initialized when the BasicAtom instance is constructed. If all terms are ground, it is set to true, otherwise to false. https://github.com/alpha-asp/Alpha/blob/master/src/main/java/at/ac/tuwien/kr/alpha/common/atoms/BasicAtom.java#L64

Since BasicAtom.getTerms() returns the atom´s internal modifiable list of terms, these terms can be modified later, it may even happen that ground atoms become non-ground. Thereby, the whole atom becomes non-ground, which is then not reflected in BasicAtom.ground.

This happens, for example, in IntervalTermToIntervalAtom.rewriteIntervalSpecifications(Rule). Therefore, interval rewriting has to be adapted when atoms become immutable.

rtaupe avatar Nov 01 '18 16:11 rtaupe