abuse of lambda question
Michael Hudson
mwh21 at cam.ac.uk
Wed Jun 7 18:53:51 EDT 2000
Before we start: you're a sick man.
Ben Wolfson <rumjuggler at cryptarchy.org> writes:
> I'm attempting to abuse Python's lambdas, and I've come across a
> problem I can't figure out. Well, the problem is actually that I'm
> attempting to abuse lambdas, but aside from that I don't know why the
> abuse is failing. Here's what I've got:
>
> def __everyother(): #factory to return lambdas.
> return lambda l, evens, odds, app=lambda a,e: lambda
> a=a,e=e:a.append(e): Compose(apply(map, (lambda e, evens=evens,
> odds=odds, l=l,app=app: If(l.index(e)%2==0, app(evens,e), app(odds,e))
> ,l)), Return(evens, odds))
>
> The functions it calls are:
>
> def Return(*args):
> return lambda args=args: args
>
> def Compose(*args):
> return lambda fs=args: For(len(fs), lambda c, fs=fs:
> If(lambda c=c,fs=fs: c==len(fs)-1, Return(fs[-1]()), fs[c]))()
>
> def For(count, fct, *args, **kwargs):
> for i in range(count):
> fct(i,*args,**kwargs)
You don't post the code for If, and I'm a bit confused, because in one
place:
> odds=odds, l=l,app=app: If(l.index(e)%2==0, app(evens,e), app(odds,e))
you pass a value as the first parameter, and in another:
> If(lambda c=c,fs=fs: c==len(fs)-1, Return(fs[-1]()), fs[c]))()
you pass a thunk. Which do you want? I suspect this may be giving
the error you're suffering, though I can't get it to work at all.
Also:
> a=a,e=e:a.append(e): Compose(apply(map, (lambda e, evens=evens,
^^^^^
what's this apply for?
i'm-sure-this-is-good-practice-for-a-maths-exam-ly y'rs
Michael
--
I also fondly recall Paris because that's where I learned to
debug Zetalisp while drunk. -- Olin Shivers
More information about the Python-list
mailing list