Weird way to declare variables
a5kin opened this issue · comments
Right now, we should declare variables in a really weird way, in order to work properly.
def absorb(self):
self.__class__.intvar = IntegerVariable()
self.intvar = self.main.state
self.main.state = -self.intvar
Have to fix it to work as follows:
def absorb(self):
self.intvar = IntegerVariable()
self.intvar = self.main.state
self.main.state = -self.intvar
Variables behavior as class descriptors has been fixed. Now it generates correct code with variable name. In case you need direct assignments to variables, it is much more convenient to declare a variable at the class level, then reuse them in emit/absorb functions just like that:
class InvertCA(core.CellularAutomaton):
state = core.IntegerProperty(max_val=1)
intvar = IntegerVariable()
class Topology:
dimensions = 2
lattice = core.OrthogonalLattice()
neighborhood = core.MooreNeighborhood()
border = core.TorusBorder()
def emit(self):
"""Do nothing at emit phase."""
def absorb(self):
"""Invert cell's value."""
self.intvar = self.main.state
self.main.state = -self.intvar