Unpacking extension (Re: A small inconsistency in syntax?)

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Oct 31 20:19:50 EST 2001


Rainer Deyke wrote:
> 
> "Greg Ewing" <greg at cosc.canterbury.ac.nz> wrote in message
> news:3BDF7571.5D8CB310 at cosc.canterbury.ac.nz...
> >    case foo:
> >      Nothing():
> >        print "We got nada"
> >      Pair(Furble(p, q), Furble(r, s)):
> >        print "We got a pair of furbles"
> >      Pair(a, b):
> >        print "We got a pair of something else"
> >      x:
> >        print "We got something else"
> 
> Ambiguous to the point of uselessness.
>
> a, b = 7, 13
> case foo:
>   Pair(a, b):
>     print 'Got Pair(7, 13)'

No. Bare names in argument positions would always be 
interpreted as names to be bound.

A possible extension would be to allow constants in
argument positions, so

 case foo:
   Pair(7, 13):
     print 'Got Pair(7, 13)'

Another possible extension would be to provide a way
to mark an argument for evaluation, maybe

 a, b = 7, 13
 case foo:
   Pair(+a, +b):
     print 'Got Pair(7, 13)'

-- 
Greg Ewing, Computer Science Dept, University of Canterbury,	  
Christchurch, New Zealand
To get my email address, please visit my web page:	  
http://www.cosc.canterbury.ac.nz/~greg



More information about the Python-list mailing list