Replacement for lambda - 'def' as an expression?

Paul Rubin http
Wed Sep 7 09:01:09 CEST 2005

Simo Melenius <firstname.lastname at> writes:
> But if you could do anonymous blocks, you could just write something
> like:
> def generate_randomizer (n, m):
>     return def (x):
>         return pow (x, n, m)

Yes, as it stands you can already say:

   def generate_randomizer(n, m):
     return lambda x: pow(x, n, m)

I was showing that it can also be done with a named internal function.

> Sure, you don't lose any expressiveness in that: if you had to name
> any object before using it, you could write all the same programs that
> you can in the current Python. But it's the expressiveness of your
> mind that gets harpooned: you'll have to keep part of your focus on
> these extraneous local variables instead of thinking only in terms
> of values where only values matter.

Yes, I agree with this.

More information about the Python-list mailing list