[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accumulator

On Thu, 23 May 2002, Paul Prescod wrote:

> Anything that can be done with lambda can be done without it, because
> these two statements are equivalent:
> _ = lambda y: y
> def _(y):
> 	...
> Python's goal is regularity and readability, not succinctness.

Just to clarify - what I think you mean is that anything that can be done
with *Python's limited form of lambda* can be done without it, since inner
functions have the same restrictions lambda does.

> Anyhow, let's suppose that you are right and I am wrong about the
> uselessness of lambda. All of your examples of where lambda is
> appropriate are places where all you need is Python's lambda (not a more
> general block-holding, context-mutating lambda). If you want more, then
> you probably are using lambda in a context that would make sense to a
> Lisp programmer but not a Python programmer.

Paul, I'm curious - what is the idiomatic Python equivalent to
continuation-passing-style?  I honestly can't imagine a way to write code
in CPS not using lambda (that is, a full, "context-mutating" lambda)
without it being horribly ugly to the point of unreadability.  Even given
that Python doesn't have full first class continuations (does stackless?
or are they just co-routines?), can it reasonably simulate them?

If it can't, and I have a hard time seeing how it could, then that is a
huge blow to its power and usefulness for what I do, which is build web
applications.  You will argue that thousands upon thousands of people
write web applications in Python, or other languages without
continuations, which is true - that doesn't stop me from being able to
consistently underbid them because I use more powerful tools.

(BTW, I looked at
http://www.ps.uni-sb.de/~duchier/python/continuations.html, which
discusses CPS in Python, but the example it gives happens not to do any
mutation, so it gets away with using Python's lambda - and even then,
states "What becomes evident in the above is that Python's lack of real
closures makes it a bit painful to write what in a functional language is
truly succinct and elegant.").