> 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
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