[Python-ideas] Ruby-style Blocks in Python Idea
steve at pearwood.info
Wed Mar 11 13:03:58 CET 2009
On Wed, 11 Mar 2009 11:01:41 am average wrote:
> These kind of [Anonymous] functions/code blocks explicitly tell the
> user that "This is NOT part of my program"
I'm a user, and they don't tell me any such thing.
By the way, that word, "explicitly" -- I think you are
using "explicitly" as if it actually meant "implicitly". If the
function were to explicitly tell the user, it would look something like
caller( function_that_is_not_part_of_the_program x: x+1 )
which of course is ridiculously verbose. What you say might be true if
lambda had that extended meaning, but it doesn't. In Python, lambda
merely means "create a nameless function object from a single
It's also nonsense, because there the function is, inside the program as
clear as day. Arguing that a function that appears inside your program
is not part of your program is rather like saying that your stomach is
not part of your body.
Perhaps what you are getting at is that anonymous functions blur the
difference between code and data, and that if you consider them as
data, then they are outside the program in some sense? That's not
entirely unreasonable: it's common to distinguish between code and
data, even though fundamentally they're all just bits and, really, the
distinction is all in our mind. (That doesn't mean the distinction
But even accepting that an anonymous function used as data is outside of
the program in some sense, anonymity is strictly irrelevant. If you
consider the lambda function here:
caller(lambda x: x+1)
to be data, then so is the named function foo here:
I'm trying to give you the benefit of the doubt.
More information about the Python-ideas