[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Carl Witty
On Sat, Mar 28, 2009 at 10:37 AM, Florent Hivert wrote: > I also like the following one because it has a very high precedence and also > because it reminds XML tags > >   [1,2,3]    [1,2,3] That one is nice; it's very pretty. Unfortunately, it doesn't work with the same implementation, because

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Florent Hivert
> I'd like to extend the above decorator to handle several different > common precedence levels, maybe just addition, multiplication, and power. You mean that you what to support the following syntaxes ? [1,2,3] +foo+ [1,2,3] [1,2,3] **foo** [1,2,3] I also like the following one becaus

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Florent Hivert
Dear Jason, > Okay, how about this: > > class inline_operator: You probably mean : class infix_operator: ... "infix" remember "infix" :) > # EXAMPLE > > a=[1,2,3] > b=[3,4,5] > > @inline_operator > def emul(a,b): > return [i*j for i,j in zip(a,b)] > > # Returns [3,8,15] > a

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Jason Grout
Florent Hivert wrote: > Dear Jason, >> Okay, how about this: >> >> class inline_operator: > > You probably mean : > > class infix_operator: > ... > > "infix" remember "infix" :) Yes. Right. Thanks. > >> # EXAMPLE >> >> a=[1,2,3] >> b=[3,4,5] >> >> @inline_operator >> def emul(a,b)

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Jason Grout
Carl Witty wrote: > On Sat, Mar 28, 2009 at 5:28 AM, Jason Grout > wrote: >> Aha, the one custom infix operator that I know of in Sage. >> >> In the backslash operator and in the article posted, the rmul only >> stored the argument and the __mul__ only performed the operation. Are >> you always

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Carl Witty
On Sat, Mar 28, 2009 at 5:28 AM, Jason Grout wrote: > Aha, the one custom infix operator that I know of in Sage. > > In the backslash operator and in the article posted, the rmul only > stored the argument and the __mul__ only performed the operation.  Are > you always guaranteed that __rmul__ wi

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Jason Grout
Robert Bradshaw wrote: > This is the same trick we use for the backslash operator in Sage. > Aha, the one custom infix operator that I know of in Sage. In the backslash operator and in the article posted, the rmul only stored the argument and the __mul__ only performed the operation. Are yo

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Jason Grout
Florent Hivert 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)

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Florent Hivert
> > 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.fun

[sage-devel] Re: Custom inline operators in python

2009-03-28 Thread Robert Bradshaw
This is the same trick we use for the backslash operator in Sage. - Robert On Mar 27, 2009, at 6:52 PM, David Joyner wrote: > > 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! > >

[sage-devel] Re: Custom inline operators in python

2009-03-27 Thread Hazem
You're welcome to all of you. I guess all those hours spent online didn't go to waste :) Hazem On Mar 27, 9:52 pm, David Joyner wrote: > 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. Th

[sage-devel] Re: Custom inline operators in python

2009-03-27 Thread David Joyner
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 wrote: > ... > > One thing that I thought was very interesting was their way of allowing > f