syntax difference

Alister alister.ware at ntlworld.com
Thu Jun 21 14:01:58 EDT 2018


On Wed, 20 Jun 2018 11:41:23 -0700, bart4858 wrote:

> The actual interpreter code is irrelevant. Switch would be a feature of
> the language being interpreted, not of the interpreter.
> 
> If the task is to match an expression X against a variety of values,
> then expressing that as a switch means the interpreter /could/ use a
> jump table (of labels within the byte code), rather than execute a chain
> of X==Y tests within byte code. So, evaluate X once then it could be a
> single byte code op.
> 
> At least, it will know that exactly the same X value is being tested. So
> you evaluate it once then keep it on the stack.
> 
> Think of Switch as another kind if hint.

which can be implemented in python by putting function calls as members 
of a list or dictionary

switch=[case1,case2,case3]
switch[a]()

(although i personally would still like to see a switch if anyone can 
come up with a suitable syntax that does not break the rest of the python 
philosophy wtr indentation.)



-- 
There are more things in heaven and earth,
Horatio, than are dreamt of in your philosophy.
		-- Wm. Shakespeare, "Hamlet"



More information about the Python-list mailing list