Currying in Python
Kiuhnm
kiuhnm03.4t.yahoo.it
Tue Mar 20 06:13:23 EDT 2012
On 3/20/2012 8:11, Arnaud Delobelle wrote:
> On 19 March 2012 23:20, Ian Kelly<ian.g.kelly at gmail.com> wrote:
>> I hope you don't mind if I critique your code a bit!
>>
>> On Fri, Mar 16, 2012 at 7:21 PM, Kiuhnm
>> <kiuhnm03.4t.yahoo.it at mail.python.org> wrote:
>>> Here we go.
>>>
>>> --->
>>> def genCur(f, unique = True, minArgs = -1):
>>
>> It is customary in Python for unsupplied arguments with no default to
>> use the value None, not -1. That's what it exists for.
>>
>>> """ Generates a 'curried' version of a function. """
>>> def geng(curArgs, curKwargs):
>>> def g(*args, **kwargs):
>>> nonlocal f, curArgs, curKwargs, minArgs; # our STATIC data
>
> I don't know if all the rest of the code is below, but this line above
> would only be necessary if you want to rebind f, curArgs, minArgs.
> You don't seem to do it, so I think this line is unnecessary.
What a coincidence. I was just telling that to Ian Kelly. I removed it
from the code in my article a few days ago but forgot to update my post
on this ng.
> Also, your naming of variables disagrees with PEP 8 :)
>
>>> if len(args) or len(kwargs):
>>
>> Collections evaluate as true if they are not empty, so this could just be:
>>
>> if args or kwargs:
>>
>>> # Allocates data for the next 'g'. We don't want to modify our
>>> # static data.
>>> newArgs = curArgs[:];
>
> Semicolon to end a statement?
As above. Too many years of C++.
Kiuhnm
More information about the Python-list
mailing list