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

Bjorn Pettersen BPettersen at NAREX.com
Fri Mar 29 21:10:46 EST 2002


> From: Steven Majewski [mailto:sdm7g at Virginia.EDU]
> 
> On Fri, 29 Mar 2002, Bjorn Pettersen wrote:
> 
> > > From: Steve Lamb [mailto:grey at despair.dmiyu.org]
> > >
> > > 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.
> >
> 
> table = {}
> 
> table[key] = func, (args,...)
> ...
> 
> def doit( k ):
> 	return table[k][0]( *table[k][1] )

Point taken, but is this an argument for or against the match/switch
statement <wink>?

Personally, I don't think it's worth adding a match statement unless we
can have ML style pattern matching...

Not-sure-what-a-good-Pythonic-spelling-would-be-though'ly y'rs
-- bjorn




More information about the Python-list mailing list