A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-November/018416.html below:

[Python-Dev] switch-based programming in Python

[Python-Dev] switch-based programming in Python [Python-Dev] switch-based programming in PythonM.-A. Lemburg mal@lemburg.com
Thu, 08 Nov 2001 09:50:59 +0100
"Martin v. Loewis" wrote:
> 
> > Wouldn't it make sense to enable the byte code compiler to take the
> > above construct and turn it into a dictionary based switch statement
> > ?
> 
> That won't work. You cannot know what type "x" has, so you don't know
> in advance how "x == 'one'" is evaluated.

But you do know that x won't change from one compare to the next,
so a single dictionary lookup could replace the equality tests
(provided that x is hashable).

As mentioned in the posting: the compiler probably has to be given 
some extra information to enable this sort of optimization. I'm not
sure how the information could be "encoded", though. Suggestions
are appreciated, as always :-)

What do you think about the general idea, BTW ?

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4