However if these semantics were brought into the core language I'd be very happy.
However if these semantics were brought into the core language I'd be very happy.
Yeah, I admit part of me felt dirty implementing this by commandeering operators. But my brief time with Haskell and F# has biased me enough toward this style of function composition that I preferred to deal with the ugliness of my hack, rather than the ugliness of not being able to express certain functions in this style in my other toy projects. :)
I agree though, hopefully the language itself will support this one day, and then my ugly hack can go away. (I swear, Python always seems to stop just shy of being a fantastic little dynamic fp language...)
Thanks for the feedback!
Overloading these operators on function objects really isn't the end of the world. It's not like these operators were being used for anything, and sometimes this kind of DSL-ish extension can be good. It's certainly more reasonable than the goto module, which uses horrid bytecode hax to get the job done.
If you want this in the language, write to the python-ideas mailing list, and then draft a PEP if you get any support. Good luck!
+1 here, but I'm not holding my breath. Python's BFDL has been hostile to making lambda more powerful; I'm not sure what he would think about this.
I think the syntax is fine. The star operator already is sensitive to the operands, so you're not impairing readability at all.
There's going to be a lot of overhead with this kind of thing, but did you have another reason?
All that code is executing on every partial call. So, a very brief list of reasons not to use this in production:
1. overhead
2. complexity
3. debugging
4. don't fight the language
edited to add: I just want to emphasize that I think it's a really, really neat hack!
edit: In other words, "Don't fight the language" as another commenter said.