[Python-Dev] PEP 275: "Switching on Multiple Values", Rev 1.1

M.-A. Lemburg mal@lemburg.com
Thu, 15 Nov 2001 10:00:08 +0100


Thomas Wouters wrote:
> 
> On Tue, Nov 13, 2001 at 03:32:55PM +0100, Jack Jansen wrote:
> 
> > Even though I'm not sure I like the switch idea (and I won't even contemplate
> > how Guido will react when he comes back and sees what we've been spending our
> > time on:-) there's one very special case of switch that I would like, and
> > that's the Algol 68 style switch on type. If we had something like
> >   def foo(x):
> >      switch type(x):
> >         case int:
> >           do something
> >         case string:
> >           do something else
> > this would be a nice point to hook into for something that tries to compile
> > Python to C or somesuch.
> 
> Unfortunately, type-names/objects aren't compile-time constants, so we can't
> implement this without some kind of namespace-modification-notification
> technique. Hmm... Or perhaps we could do the normal lookup, compare the
> then-current 'int' vs. the one we looked up, and if they aren't equal
> re-initialize the jump dict.... But *shudder*.

Dang. You're right -- I overlooked that "detail". Which brings us back
to the discussion about optimizing builtin and module global 
lookups... it would be really really nice if Python had a mechanism
which would allow to mark those symbols read-only or at least
as "pre-fetching these at code object creation time is allowed"
(this wouldn't help us with the switch statement, but has some other
nice advantages, e.g. avoiding global lookups at run-time).

Oh well...

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/