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

Bruce Leban bruce at leapyear.org
Wed Feb 12 01:00:00 CET 2014


On Tue, Feb 11, 2014 at 3:51 PM, Ryan Gonzalez <rymg19 at gmail.com> wrote:

> Uhhh...isn't that the same as a lambda? i.e.:
>


I knew I should have thrown something else in there more than 'return' to
show I wasn't just doing lambda. See added lines below.

def sample(i, op, j):
    switcher = {{
       '-':: if i > j:
                 return i - j
             else:
                 return j - i;;
       '+':: return i + j;;

       '*':: result = 1

             for k in range(j):

                 result += i

             return result;;

       '@':: print(i, j)
             raise OopsException();;

    }}
    return switcher[op]()


I also left out the default case for simplicity.

On Tue, Feb 11, 2014 at 3:47 PM, Andrew Barnert <abarnert at yahoo.com> wrote:

> <snip> It's not an accident that the provisional syntax is ugly </snip>
>

You think that's ugly? I can make it uglier.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140211/6cce744d/attachment.html>


More information about the Python-ideas mailing list