Merge_history (from Explicable) and develop_steps (from Expression)

work together
This commit is contained in:
Benjamin Bertrand
2016-03-07 13:05:12 +03:00
parent bfef87424d
commit 976cbbdf03
2 changed files with 47 additions and 24 deletions

View File

@@ -19,12 +19,12 @@ class Explicable(Renderable):
def __init__(self, *args, **kwargs):
super(Explicable, self).__init__()
self.steps = []
self.explainator = 0
self.explained = 0
def explain(self):
r""" Generate and render steps which leed to itself
After beening explained, the Explicable become amnesiac.
After beening explained, the Explicable become amnesiac. It will return itself in a list.
See 'history_generator' to explain it once again.
>>> action = Explicable()
@@ -39,12 +39,19 @@ class Explicable(Renderable):
>>> # Now action is amnesiac
>>> for i in action.explain():
... print(i)
42
>>> action = Explicable()
>>> action.postfix_tokens = Expression('42')
>>> for i in action.explain():
... print(i)
42
"""
if not self.explainator:
self.explainator = self.history_generator()
return self.explainator
if self.explained:
return [self.STR_RENDER(self.postfix_tokens)]
else:
self.explained = 1
return self.history_generator()
def history_generator(self):
r""" Generator for rendered steps which leed to itself
@@ -145,9 +152,14 @@ class Explicable(Renderable):
['2 + 10 \\times 4', '2 \\times 12']
['2 + 40', '24']
['42', '24']
>>> # Now they are amnesiac
>>> for i in action1.explain():
... print(i)
42
>>> m_history = Explicable().merge_history([action1, action2])
>>> for i in m_history:
... print(i)
['42', '24']
>>> action1 = Explicable()
>>> action1.postfix_tokens = Expression('42')
>>> action1.this_append_before([Expression('2+10*4'), Expression('2+40')])
@@ -174,6 +186,10 @@ class Explicable(Renderable):
['2 + 10 \\times 4', '2 \\times 12', '3 - 3']
['2 + 40', '24', '0']
['42', '24', '0']
>>> m_history = Explicable().merge_history([1,2,3])
>>> for i in m_history:
... print(i)
[1, 2, 3]
"""
steps = []
for expl in explicables: