[Python-ideas] combining two threads: switch statements and inline functions

Chris Angelico rosuav at gmail.com
Wed Feb 12 01:17:03 CET 2014


On Wed, Feb 12, 2014 at 10:51 AM, Ryan Gonzalez <rymg19 at gmail.com> wrote:
> Uhhh...isn't that the same as a lambda? i.e.:
>
> def sample(i, op, j):
>     return {'+': lambda: i+j,
>               '-': lambda: i-j if i>j else j-i
> }[op]

I was thinking it would be possible to craft a syntax more like the
OP's but which, courtesy of MacroPy or something, translated into the
version I gave. That way, it's not a nested function, which has
scoping and traceback implications.

ChrisA


More information about the Python-ideas mailing list