[Python-ideas] Ruby-style Blocks in Python Idea
Steven D'Aprano
steve at pearwood.info
Mon Mar 9 18:03:04 CET 2009
On Tue, 10 Mar 2009 03:43:03 am average wrote:
> While there are several complaining that all this can be done with a
> def, there's an critical distinction being overlooked. Passing
> around code blocks is a very different style of programming that
> Python or most languages like it have ever experimented with. The
> programming art itself hasn't really even explored the different
> range of thinking this style of programming opens up. Where as most
> function
> definitions are verb-like, this would be a noun-like definition.
> Akin perhaps to the difference between a hormone in the body and a
> neurotransmitter, respectively.Setting it off with a new keyword, or
> expanding the use of lambda is really a mandatory way of signifying
> this INTENT.
Marcos, I'm afraid that I don't understand your analogy, or your
argument. An anonymous code block is just like a named function, except
it doesn't have a name. Can you explain why:
func(named_function)
is radically different from:
func(multi-line-code-block-without-the-name)
please? We can already do this in Python, using functions made up of a
single expression:
func(lambda: expr)
I use this frequently, because it is sometimes convenient, but there is
nothing I can do with a lambda that I can't do with a named function. I
don't see that introducing multi-lined lambdas will change that.
I'm trying to keep an open-mind here, but I also don't understand your
analogy. In what way are named functions like neurotransmitters, or
hormones? Which one is supposed to be verb-like and which one is
noun-like? What does that even mean?
--
Steven D'Aprano
More information about the Python-ideas
mailing list