Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21922
| Date | 2012-03-20 11:13 +0100 |
|---|---|
| From | Kiuhnm <kiuhnm03.4t.yahoo.it> |
| Newsgroups | comp.lang.python |
| Subject | Re: Currying in Python |
| References | <4f63e724$0$1386$4fafbaef@reader1.news.tin.it> <CALwzidndq-u4hqK8GDXoCDQhT22fDJbaiFkmgrQvv=gAs0i4EQ@mail.gmail.com> <mailman.822.1332227523.3037.python-list@python.org> |
| Message-ID | <4f685843$0$1374$4fafbaef@reader1.news.tin.it> (permalink) |
| Organization | TIN.IT (http://www.tin.it) |
On 3/20/2012 8:11, Arnaud Delobelle wrote: > On 19 March 2012 23:20, Ian Kelly<ian.g.kelly@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@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Currying in Python Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-17 02:21 +0100
Re: Currying in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-17 01:46 +0000
Re: Currying in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-17 02:14 +0000
Re: Currying in Python Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-19 00:49 +0100
Re: Currying in Python Ian Kelly <ian.g.kelly@gmail.com> - 2012-03-19 17:20 -0600
Re: Currying in Python Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-20 01:24 +0100
Re: Currying in Python Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-20 02:13 +0100
Re: Currying in Python Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-20 11:06 +0100
Re: Currying in Python Arnaud Delobelle <arnodel@gmail.com> - 2012-03-20 07:11 +0000
Re: Currying in Python Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-20 11:13 +0100
csiph-web