[Python-Dev] Switch statement

M.-A. Lemburg mal at egenix.com
Mon Jun 12 19:30:55 CEST 2006


Thomas Lee wrote:
> Hi all,
> 
> As the subject of this e-mail says, the attached patch adds a "switch"
> statement to the Python language.
> 
> However, I've been reading through PEP 275 and it seems that the PEP
> calls for a new opcode - SWITCH - to be added to support the new
> construct.
> 
> I got a bit lost as to why the SWITCH opcode is necessary for the
> implementation of the PEP. The reasoning seems to be
> improving performance, but I'm not sure how a new opcode could improve
> performance.
> 
> Anybody care to take the time to explain this to me, perhaps within the
> context of my patch?

Could you upload your patch to SourceForge ? Then I could add
it to the PEP.

Thomas wrote a patch which implemented the switch statement
using an opcode. The reason was probably that switch works
a lot like e.g. the for-loop which also opens a new block.

Could you explain how your patch works ?

BTW, I think this part doesn't belong into the patch:

> Index: Lib/distutils/extension.py
> ===================================================================
> --- Lib/distutils/extension.py	(revision 46818)
> +++ Lib/distutils/extension.py	(working copy)
> @@ -185,31 +185,31 @@
>                  continue
>  
>              suffix = os.path.splitext(word)[1]
> -            switch = word[0:2] ; value = word[2:]
> +            switch_word = word[0:2] ; value = word[2:]

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jun 12 2006)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2006-07-03: EuroPython 2006, CERN, Switzerland              20 days left

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::


More information about the Python-Dev mailing list