Partially evaluated functions

Scottie me at nospam.net
Thu Jul 12 04:52:29 EDT 2001


"Nick Perkins" <nperkins7 at home.com> wrote in message
news:iS5Y6.296363$eK2.60388388 at news4.rdc1.on.home.com...
> ...The cookbook version is the only one ...which gives priority to kw
> args supplied at call-time over args supplied at create-time....
> def f(color='black'): print color
> f2 = curry(f,color='blue')
> f2(color='red')
>
> The cookbook version will print 'red', Rainer and Alex both print 'blue'.
> (easy to change, of course)
Not so easy if you want to avoid the copy:

def go(curry):
    def fn(a=1,b=2,c=3):
        print a, b, c
    f1 = curry(f,a=4,c=5)
    f1()
    f1(a=6)
    f1(c=9)

I want this to print:
4 2 5
6 2 5
4 2 9

The others print:
4 2 5
4 2 5
4 2 5

If you do the obvious, you'll get:
4 2 5
6 2 5
6 2 9

-Scott David Daniels
Scott.Daniels at Acm.Org



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.264 / Virus Database: 136 - Release Date: 7/2/2001





More information about the Python-list mailing list