A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-June/054169.html below:

[Python-Dev] Multiple expression eval in compound if statement?

[Python-Dev] Multiple expression eval in compound if statement? [Python-Dev] Multiple expression eval in compound if statement?Raymond Hettinger python at rcn.com
Mon Jun 13 04:20:31 CEST 2005
> I'm horsing around with recognizing switch-like if statements like:
> 
>     if x == 1:
>         print 1
>     elif x == 2:
>         print 2
>     else:
>         print "unknown"
> 
> in the compiler and generating O(1) code.  "x" can be any expression,
but
> must be precisely the same in each elif clause, the comparison
operator
> must
> be "==" and the RHS of the test must evaluate to a simple hashable
> constant
> (string, float, integer - still working on None, constant tuples may
be
> allowed later).  I can currently recognize such constructs and am
working
> on
> code generation.

I think it unwise to allow x to be any expression.  Besides altering
existing semantics, it leads to code redundancy and to a fragile
construct (where the slightest alteration of any of the expressions
triggers a silent reversion to O(n) behavior).


Raymond
More information about the Python-Dev mailing list

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