[Python-ideas] Enhance definition of functions

Andrew Barnert abarnert at yahoo.com
Wed Jul 31 08:30:58 CEST 2013


On Jul 30, 2013, at 11:30, Ryan <rymg19 at gmail.com> wrote:

> How about something like:
> 
> f = indef(x, y): print x, y
> 
> It's essentially storing lambdas.

You can already store lambdas. 

Or, more precisely, you can store functions. A lambda isn't a type; it's just a different way of creating functions, exactly the same type of functions you get from the def statement. And functions are first class values that can be bound to a name just like any other value.

Meanwhile, the only advantages of lambda over def are that you don't have to come up with a name, and you can use it in an expression. So, trying to come up with a statement for giving lambdas names implies that there's something fundamental you're missing that would make your life a lot easier. Maybe you didn't know you could use def locally? Or you're trying to build code out of eval-ing strings because you don't know about closures? Or... Well, there are lots of possibilities. If you explain what you want to do that you think your new syntax would help with, I'm 99% sure Python already has a better way to do it.


More information about the Python-ideas mailing list