Another stab at a "switch/case" construct (for Python 3000):

Bjorn Pettersen BPettersen at NAREX.com
Fri Mar 29 16:24:30 EST 2002


> From: Steve Lamb [mailto:grey at despair.dmiyu.org] 
> 
> On Fri, 29 Mar 2002 10:48:15 GMT, Benjamin Schollnick 
> <junkster at rochester.rr.com> wrote:
> > IF X == 0:
> >    DO_THIS ()
> > ELIF X == 2:

[snip]

> > But, this routine is not exactly readable compared to a case:
>  
> > CASE X of:
> >    0  : DO_THIS()
> >    2  : DO_THIS (2)
> >    4  : DO_THIS (x+2)
> >    6  : DO_THIS ()
> >  ELSE:
> >       DO_NOT_DO_THIS()
> 
> its_called_a_directory_pointing_to_functions = {'case':closed}
> 
>     I do not believe that any language which can have a hash 
> of function pointers has any business with a case statement.

But that only works when all the functions in all the branches take the
same number and types of arguments -- hardly the general case.

-- bjorn




More information about the Python-list mailing list