control structures (was "Re: Sins")

skaller skaller at maxtal.com.au
Sat Jan 8 10:01:15 EST 2000


Darrell wrote:
> 
> Using an exception as a "switch" statement is a cool idea.
> A dictionary approach comes to mind, with so many states.

Yeah, this will be MUCH faster for large switches,
because hashing is typically very fast, and hashtable
lookup is more or less constant time.

What would be 'generally' useful is a genuine switch 
statement -- a sort of unrolled dictionary whose values
are pieces of code. Syntax?

	switch x:
	case 1: ..
	case 2: ...
	default: ...

like C, except that each handler has an implicit
break at the end of the handler suite (no fall through,
like in C).

Comments?

-- 
John (Max) Skaller, mailto:skaller at maxtal.com.au
10/1 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
voice: 61-2-9660-0850




More information about the Python-list mailing list