Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from ladon.ladonizer import ladonize
- from ladon.types.ladontype import LadonType
- class Complex(LadonType):
- r = float
- i = float
- def __init__(self,r=None, i=None, **kw):
- # ASSIGNEMTS
- # Class-local assignments
- self.r = r
- self.i = i
- # prime_dict based assignments
- LadonType.__init__(self,**kw)
- def __repr__(self):
- return "(%g+%gj)" % (self.r, self.i)
- class Calculator(object):
- """
- This service does the math, and serves as example for new potential Ladon users.
- """
- @ladonize(int,int,rtype=int)
- def add(self,a,b):
- """
- Add two integers together and return the result.
- @param a: 1st integer.
- @param b: 2nd integer.
- @rtype: The result of the addition
- """
- return a+b
- @ladonize([int],rtype=int)
- def add_many(self, args):
- """
- Add integers together and return the result
- @param args: integer
- @rtype: The result of the addition
- """
- return reduce(lambda x, y: x+y, args)
- @ladonize(Complex, Complex, rtype=Complex)
- def add_complex(self, a, b):
- """ Add two complex numbers and return the result
- @param a: 1st complex number
- @param b: 2nd complex number
- @rtype: The result of the addition
- """
- #ret = complex(a.r, a.i) + complex(b.r, b.i)
- #return Complex(ret.real, ret.imag)
- return a
- if __name__ == "__main__":
- c = Calculator()
- a = Complex(0, 1)
- b = Complex(1, 0)
- print c.add_complex(a, b)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement