On 6/21/06, Phillip J. Eby <[EMAIL PROTECTED]> wrote:
> At 03:38 AM 6/21/2006 -0500, Ka-Ping Yee wrote:
> >On Wed, 21 Jun 2006, Phillip J. Eby wrote:
> > > Well, EIBTI and all that:
> > >
> > >      switch x:
> > >          case == 1: foo(x)
> > >          case in S: bar(x)
> > >
> > > It even lines up nicely.  :)
> >
> >Hmm, this is rather nice.  I can imagine possible use cases for
> >
> >     switch x:
> >         case > 3: foo(x)
> >         case is y: spam(x)
> >         case == z: eggs(x)
> >
> >An interesting use case for which this offers no corresponding
> >syntax is
> >
> >         case instanceof ClassA: ham(x)
>
> Actually, I was assuming that any other operator besides == and 'in' would
> be relegated to an if-elif chain in the default case, although it's almost
> possible to do that automatically, I suppose.

I've been thinking about generalization to other operators too, but
decided that it would be a mistake. It would be quite clumsy to
explain the exact semantics: if all operators are "==" or "in" an
efficient hash table gets pre-constructed at function definition time,
otherwise, um..., what exactly?

(Note how I've switched to the switch-for-efficiency camp, since it
seems better to have clear semantics and a clear reason for the syntax
to be different from if/elif chains.)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to