Re: switch/case (was Re: Want, wrapper subs and context preservation)

[email protected] (Damian Conway) Mon, 7 Aug 2000 17:18:07 +1000 (EST)
Newsgroups perl.perl6.language.subs
Message-ID <[email protected]>
   > On Mon, Aug 07, 2000 at 05:49:37AM +1000, Damian Conway wrote:
   > >   switch ([want]) {
   > > 	case 'LIST' 	{ @ret = &wrapped }
   > > 	case 'SCALAR'	{ $ret = &wrapped }
   > > 	else		{ &wrapped }
   > >   }
   > 
   > cases have elses? 

They're not necessary. The same example could be:

   switch ([want]) {
    	case 'LIST' 	{ @ret = &wrapped }
   	case 'SCALAR'	{ $ret = &wrapped }
   	&wrapped
   }
   
   > If so, why use a new word rather than hijacking
   > "if" to do the right thing inside of a switch block?  Perl is already
   > super context-sensitive anyway.

You've just convinced me to take else's out of the proposal! ;-)
  
   > And do switches have elses? (meaning none of the cases were satisfied)

Yes. See the example above :-)

Damian