Rough check that the embedded program in the object is valid.
(self)
| 298 | return None |
| 299 | |
| 300 | def validate_program(self): |
| 301 | """Rough check that the embedded program in the object is valid.""" |
| 302 | terminals = [0] |
| 303 | for node in self.program: |
| 304 | if isinstance(node, _Function): |
| 305 | terminals.append(node.arity) |
| 306 | else: |
| 307 | terminals[-1] -= 1 |
| 308 | while terminals[-1] == 0: |
| 309 | terminals.pop() |
| 310 | terminals[-1] -= 1 |
| 311 | return terminals == [-1] |
| 312 | |
| 313 | def __str__(self): |
| 314 | """Overloads `print` output of the object to resemble a LISP tree.""" |