[Python-ideas] Infix functions
Ryan Gonzalez
rymg19 at gmail.com
Sat Feb 22 03:02:58 CET 2014
More information about the Python-ideas mailing list
Sat Feb 22 03:02:58 CET 2014
- Previous message: [Python-ideas] Infix functions
- Next message: [Python-ideas] Infix functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
You should contribute that to PyExt(https://github.com/kirbyfan64/pyext). I'd love to have it there. On Fri, Feb 21, 2014 at 7:45 PM, Mathias Panzenböck < grosser.meister.morti at gmx.net> wrote: > Am 2014-02-21 23:05, schrieb Andrew Barnert: > > While we're discussing crazy ideas inspired by a combination of a >> long-abandoned PEP and Haskell idioms (see the implicit lambda thread), >> here's another: arbitrary infix operators: >> >> a `foo` b == foo(a, b) >> >> > If you really want to you could do this: > > class infix(object): > __slots__ = '__call__', > > def __init__(self,func): > self.__call__ = func > > def __ror__(self,arg1): > return infix2(self.__call__, arg1) > > class infix2(object): > __slots__ = 'func', 'arg1' > > def __init__(self,func,arg1): > self.func = func > self.arg1 = arg1 > > def __call__(*args,**kwargs): > self, args = args[0], args[1:] > return self.func(self.arg1,*args,**kwargs) > > def __or__(self,arg2): > return self.func(self.arg1,arg2) > > @infix > def foo(a,b): > return a + b > > print "egg" |foo| "spam" > > > _______________________________________________ > Python-ideas mailing list > Python-ideas at python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Ryan If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated." -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140221/ae76f9ca/attachment-0001.html>
- Previous message: [Python-ideas] Infix functions
- Next message: [Python-ideas] Infix functions
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-ideas mailing list