[Python-ideas] And now for something completely different
veloso at verylowsodium.com
Fri Sep 19 22:06:29 CEST 2008
On Fri, Sep 19, 2008 at 3:08 PM, Cliff Wells <cliff at develix.com> wrote:
> On Fri, 2008-09-19 at 13:14 +1200, Greg Ewing wrote:
>> The only way I could see this working is if deferred arguments
>> are marked at *both* the calling and called sites. Then the
>> compiler knows what code to generate, and the called function
>> can check that it has been passed the right kind of argument.
> Actually, that might just be acceptable (if not my preferred form). It
> meets my desire to enforce lazy evaluation although it retains the ugly
> lambda in the caller.
But once you accept that deferred arguments must be marked at the call
site, you no longer need any additions to Python. The approach Bruce
Leban suggested upthread is sufficient -- wrap your deferred arguments
in a lambda, and call to expand them on the function side.
This whole discussion, with the non-starter proposal of resurrecting
backticks to solve a non-problem, reminds me of an eloquent post
earlier this year on the Lua mailing list from Fabien Fleutot:
A part of it applies here almost verbatim. With two changes to
reflect Python instead:
What drives people so crazy about it? It's not the couple of extra
keystrokes, nor the screen real estate eaten by [lambda:a+b]; it's
the fact that the current syntax carries a message they strongly
disagree with, which says: "anonymous functions are not a
lightweight feature to be used pervasively, passing them as
function parameters is not the [Python] Way, that's why it looks
syntactically odd. If you use them, it ought to be because you do
something exceptional, so your code should have a somewhat
exceptional appearance". They feel wrong when they use it, and
they think they ought to feel good.
This thread seems to be about technical solution to the "problem" that
you can't really define functions to act as new control structures in
Python. But while this may be a design choice you don't agree with,
it's not an accident, and it's not a misfeature!
Of course you could design a Python-like language that allowed users
to create their own control structures. But this would be so
different to not be at all Pythonic anymore! The fact that your new
language would be a superset of Python is beside the point. Now every
large project would have its own control structures defined. Readers
of the resulting code will have to spend more time figuring out if the
things that look like function calls actually are; reasoning about
side effects just got a lot harder.
This technical discussion is misguided. There isn't a problem here to
fix to begin with.
More information about the Python-ideas