On Mon, Aug 30, 2004, Peter Harris wrote:
I have updated PEP309 a little,
I hope there will still be time to squeeze it in before 2.4 beta 1, and if there is any reason why not (apart from there has to be a cut-off point somewhere, which I accept), please someone let me know what work is still needed to make it ready to go in.
PEP 309 is the "Partial Function Application" class. (Used to be referred to as "Currying", but that was agreed not to be an accurate name).
__________________________________________________________________________ This e-mail and the documents attached are confidential and intended solely for the addressee; it may also be privileged. If you receive this e-mail in error, please notify the sender immediately and destroy it. As its integrity cannot be secured on the Internet, the Atos Origin group liability cannot be triggered for the message content. Although the sender endeavours to maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages resulting from any virus transmitted. __________________________________________________________________________
though this might be a bit late, I would like to suggest something a bit functionally different: ---cut--- class LCurry(object): ''' this is the left curry class. ''' def __new__(cls, func, *args, **kw): obj = object.__new__(cls) if isinstance(func, LCurry) or isinstance(func, RCurry): obj._curry_func = func._curry_func obj._curry_args = (func._curry_args + args, func._curry_args) obj._curry_kw = kw = kw.copy() kw.update(func._curry_kw) else: obj._curry_func = func obj._curry_args = (args, ()) obj._curry_kw = kw.copy() return obj def __call__(self, *args, **kw): self._curry_func(*self._curry_args + args + self._curry_args, **dict(self._curry_kw.items() + kw.items()))
this mainly has one thing different from the reference implementation in the pep: 1) it is recursive that is we can curry/partial something more than one and yet avoid the extra function call per curry level...
IMO this is a worthwhile optimisation....
On Thu, 02 Sep 2004 14:49:02 -0700, Scott David Daniels email@example.com wrote:
Alex Naanou wrote:
if isinstance(func, LCurry) or isinstance(func, RCurry):
^^ is better written as: if isinstance(func, (LCurry, RCurry)):
I know! :) ...and it also is faster! but that particular code was a) written quite a while back. b) at my course at the MSU the students seem to have ALLOT less trouble understanding the existing version of the code.... (I did try both...)
yes, this is a bit of a trade-off.... need to think about it a bit more!
though this an off-topic here, but it would indeed be interesting to know if anyone has a different opinion....