Hazem wrote:
> 
> Hi everyone,
> 
> I just stumbled upon this:
> 
> http://www.pubmedcentral.nih.gov/articlerender.fcgi?artid=2644618


I thought this article was very interesting.  Thanks for posting it!

One thing that I thought was very interesting was their way of allowing 
for custom inline operators in python.  It inspired the following 
@inline_operator decorator.  Would this be useful in Sage?

class inline_operator:
     def __init__(self, function):
         self.function = function
         self.left = None
         self.right = None

     def __rmul__(self, left):
         if self.right is None:
             self.left = left
             return self
         else:
             right = self.right
             self.right = None
             return self.function(left, right)

     def __mul__(self, right):
         if self.left is None:
             self.right = right
             return self
         else:
             left = self.left
             self.left = None
             return self.function(left, right)


# EXAMPLE

a=[1,2,3]
b=[3,4,5]

# This emul operator returns the element-wise product of two lists...
@inline_operator
def emul(a,b):
     return [i*j for i,j in zip(a,b)]

# Returns [3,8,15]
a *emul* b



Thanks,

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to