[Python-Dev] PEP 3103: A Switch/Case Statement

Guido van Rossum guido at python.org
Wed Jun 28 16:45:30 CEST 2006

Looks like this doesn't help at all when pre-computing the dispatch
dict based on named constants. So this is a no-go.

I should add that ABC had such named subroutines (but not for
switching); I dropped them to simplify things. They're not an
intrinsically undesirable or even unnecessary thing IMO. But it
doesn't solve my use case for switching. The syntax is also seriously
cumbersome compared to a PEP-3103-style switch.


On 6/27/06, Talin <talin at acm.org> wrote:
> This parallels some of my thinking -- that we ought to somehow make the
> dict-building aspect of the switch statement explicit (which is better
> than implicit, as we all have been taught.)
> My version of this is to add to Python the notion of a simple
> old-fashioned subroutine - that is, a function with no arguments and no
> additional scope, which can be referred to by name. For example:
> def MyFunc( x ):
>     sub case_1:
>        ...
>     sub case_2:
>        ...
>     sub case_3:
>        ...
>     # A direct call to the subroutine:
>     do case_1
>     # An indirect call
>     y = case_2
>     do y
>     # A dispatch through a dict
>     d = dict( a=case_1, b=case_2, c_case_3 )
>     do d[ 'a' ]

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list