Why doesn't this simple Curry-like implemention work?
Joal Heagney
s713221 at student.gu.edu.au
Sun Oct 28 02:49:48 EST 2001
Paul Rubin wrote:
>
> "Michael R. Head" <burner at core.binghamton.edu> writes:
>
> > # 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've looked up on the list better class-based implementations, and am
> > using one of them, but I'm curious why this doesn't work (when the
> > curried function is called, f becomes unknown). (I'm looking for a
> > reason in the language spec). I'm supposing that lamda isn't storing
> > the reference to its inputs -- which it seems it should -- is this
> > correct?
>
> I thought the third arg to apply was a keyword arg dictionary.
> Is that really what you meant?
I tried mucking around with things, and came up with the following,
error message and all
>>> def test(value1,value2):
... print value1,value2
...
>>> def curry(f, p):
... return lambda x: apply(f, (p,x), {})
...
>>> b = curry(test, "hello")
>>> b("goodbye")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 2, in <lambda>
NameError: global name 'f' is not defined
Is this the reason for the class based curry functions?
--
Joal Heagney is: _____ _____
/\ _ __ __ _ | | _ ___ |
/__\|\ || ||__ |\ || |___|/_\|___] |
/ \ \_||__ ||___| \_|! | | \ \ !
More information about the Python-list
mailing list