Why doesn't this simle DCurry-like implementation work?

Michael R. Head burner at core.binghamton.edu
Sun Oct 28 16:19:49 CET 2001


On Sun, Oct 28, 2001 at 09:57:01AM -0500, python-list-request at python.org wrote:
> "Michael R. Head" <burner at core.binghamton.edu> wrote in message news:<mailman.1004250686.9471.python-list at python.org>...
> > # for some reason this function doesn't work in python 1.5.2.
> > def curry(f, p):
> > 	return lambda x: apply(f, p, x)
> > 
> I'm supposing that lamda isn't storing
> > the reference to its inputs -- which it seems it should -- is this
> > correct?
> > mike
> 
> Try this:
> def curry(f, p):
> 	return lambda x, ff=f, pp=p: apply(ff, pp, x)
> But i wonder if it does what you want <wink>
> 
> Joost

You are right. That's what I get for posting while drunk. I meant:

# this doesn't work...
def curry(f, p):
	return lambda x: f(p, x)

however, now I know that this does work, and does what I want:

def curry(f, p):
	return lambda x, ff=f, pp=p: ff(pp,x)

thanks all!

-- 
Michael R. Head
burner at core.binghamton.edu
GPG public key: http://www.core.binghamton.edu/~burner/gpg.key.txt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 536 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20011028/c3d25226/attachment.pgp>


More information about the Python-list mailing list