Rearrange folders and use tree2txt inside MO

This commit is contained in:
2018-03-10 08:44:01 +03:00
parent d498af2bab
commit d14850c78d
8 changed files with 54 additions and 46 deletions

View File

@@ -32,30 +32,20 @@ class MOFraction(MO):
>>> f
<MOFraction - 2 / 3>
"""
value = Tree("/",
base_value = Tree("/",
MO.factory(numerator),
MO.factory(denominator),
)
if negative:
value = Tree("-", None, base_value)
else:
value = base_value
MO.__init__(self, value)
self._numerator = numerator
self._denominator = denominator
self.negative = negative
@property
def __txt__(self):
# TODO: fonctionnement temporaire. Il faudrait utilser un moteur de rendu plus fin. |jeu. mars 8 15:26:49 EAT 2018
try:
numerator = self._numerator.__txt__
except AttributeError:
numerator = str(self._numerator)
try:
denominator = self._denominator.__txt__
except AttributeError:
denominator = str(self._denominator)
return "- "*self.negative + f"{numerator} / {denominator}"
def __add__(self, other):
""" Overload * for MOFraction

View File

@@ -6,9 +6,11 @@
#
# Distributed under terms of the MIT license.
from mapytex.calculus.core.coroutine import coroutine, STOOOP
from ..coroutine import coroutine, STOOOP
from ..renders import tree2txt
from decimal import Decimal
__all__ = ["moify", "MO", "MOstr"]
class MOError(Exception):
@@ -84,7 +86,10 @@ class MO(object):
@property
def __txt__(self):
return str(self.value)
try:
return tree2txt(self.value)
except AttributeError:
return str(self.value)
def __add__(self, other):
""" Overload + for MOs
@@ -144,6 +149,7 @@ class MO(object):
"""
return MO.factory(-self.value)
class MOnumber(MO):
""" Base number math object (int or Decimal) """
@@ -194,15 +200,12 @@ class MOstr(MO):
""" Unknown math object like x or n"""
def __init__(self, value, negative=False):
def __init__(self, value):
""" Initiate a string MO
>>> a = MOstr("x")
>>> a
<MOstr x>
>>> a = MOstr("x", negative=True)
>>> a
<MOstr -x>
>>> b = MOstr(a)
>>> b
<MOstr x>
@@ -234,13 +237,8 @@ class MOstr(MO):
raise MOError(f"An MOstr should be initiate with a alpha string, got {val}")
MO.__init__(self, value)
self.negative = negative
self.is_scalar = False
@property
def __txt__(self):
return "-"*self.negative + str(self.value)
def __add__(self, other):
raise NotImplemented
@@ -268,7 +266,7 @@ class MOstr(MO):
raise NotImplemented
def __neg__(self):
return MO(self.value, not self.negative)
pass
# -----------------------------
# Reglages pour 'vim'