This is very cool!

I remember wanting something like this awhile back but right now I
can't remember
what for. Anyway, I think it could be useful. Thanks!


On Fri, Mar 27, 2009 at 9:16 PM, Jason Grout
<jason-s...@creativetrax.com> wrote:
>

...

>
> 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