#6245: make a custom infix operator decorator
-------------------------------------------------------+--------------------
Reporter: jason | Owner: cwitty
Type: enhancement | Status:
positive_review
Priority: major | Milestone: sage-4.4
Component: misc | Keywords:
Author: Jason Grout, Carl Witty, Florent Hivert | Upstream: N/A
Reviewer: Ross Kyprianou | Merged:
Work_issues: |
-------------------------------------------------------+--------------------
Changes (by rossk):
* status: needs_review => positive_review
* reviewer: => Ross Kyprianou
Comment:
Thanks Jason - I appreciate what your code is doing a bit more now and see
where I erred - thanks for the explanation. I would think these are enough
tests to update this to a positive review.
{{{
class Fraction:
def __init__(self, numerator, denominator=1):
self.numerator = numerator
self.denominator = denominator
def __str__(self):
return "Fraction(%d,%d)" % (self.numerator, self.denominator)
__repr__=__str__
def zmul(self, other):
return Fraction(self.numerator*other.numerator,
self.denominator*other.denominator)
def __mul__(self, other):
try:
return Fraction(self.numerator*other.numerator,
self.denominator*other.denominator)
except:
return NotImplemented
def __rmul__(self, other):
try:
return Fraction(other*self.numerator,self.denominator)
except:
return NotImplemented
def dot(a,b):
return a*b
dot = infix_operator('multiply')(dot)
u = Fraction(2,3)
v = Fraction(5,4)
print u *dot* v
print 3 *dot* v
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6245#comment:16>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.