diff --git a/pymath/calculus/explicable.py b/pymath/calculus/explicable.py index 0f34494..ad3ec61 100644 --- a/pymath/calculus/explicable.py +++ b/pymath/calculus/explicable.py @@ -125,6 +125,8 @@ class Explicable(Renderable): def merge_history(expl1, expl2, operation): r""" Take two Explicable objects, explain where they are from and merge their history + This method try to use 'explain' method from expl1 and expl2. This means that after using this method, those two objects will become amnesiac. + :param expl1: fist explicable :param expl2: second explicable :param operation: the operation that link them @@ -146,11 +148,30 @@ class Explicable(Renderable): ['2 + 10 \\times 4', '2 \\times 12', +] ['2 + 40', '24', +] ['42', '24', +] + >>> for i in action1.explain(): + ... print(i) + >>> action1 = Explicable() + >>> action1.postfix_tokens = Expression('42') + >>> action1.this_append_before([Expression('2+10*4'), Expression('2+40')]) + >>> m_history = Explicable().merge_history(action1, 12, op.add) + >>> m_history + + >>> for i in m_history: + ... print(i) + ['2 + 10 \\times 4', 12, +] + ['2 + 40', 12, +] + ['42', 12, +] """ - steps1 = list(expl1.explain()) - steps2 = list(expl2.explain()) + try: + steps1 = list(expl1.explain()) + except AttributeError: + steps1 = [expl1] + try: + steps2 = list(expl2.explain()) + except AttributeError: + steps2 = [expl2] return transpose_fill([steps1, steps2, [operation]])