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/018439.html below:

[Python-Dev] switch-based programming in Python

[Python-Dev] switch-based programming in PythonMartin v. Loewis martin@v.loewis.de
Thu, 8 Nov 2001 16:55:16 +0100
> I don't think you need anything extra if the RHS of the == is a hashable
> literal of some sort and the LHS is always the same simple variable or
> subscript expression.  If the compiler can recognize the structure (that may
> be a big "if"), all you need is a dictionary of offsets stored in the
> function's constants.  You just execute the equivalent of
> 
>     offset = jumptable.get(x, E)

That won't work: It maybe that x is not hashable, even though it
compares equal with the RHS values.

Even if it was hashable, you'd change the language semantics: In the
original code, you call __cmp__, say, 20 times; in the modified code,
you call __hash__ once and __cmp__ perhaps also once. If __cmp__ has
side effects, you get a language change.

Regards,
Martin



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