> Will the proposed new want operator make writing wrapper 
   > subroutines which recreate their own context for the 
   > subroutine they are wrapping harder?

I don't see why.
   
   > For example how would the following perl 5 subroutine
   > be rewritten under perl 6 with the want operator?
   > 
   > sub wrapper {
   >   my (@ret,$ret);
   >  
   >   lock_resource();
   > 
   >   if (wantarray) {
   >     @ret = &wrapped;
   >   } elsif (defined wantarray) {
   >     $ret = &wrapped;
   >   } else {
   >     &wrapped;
   >   }
   >  
   >   unlock_resource();
   > 
   >   if (wantarray) {
   >     return @ret;
   >   } elsif (defined wantarray) {
   >     return $ret;
   >   } else {
   >     return;
   >   }
 

sub wrapper {
  my (@ret,$ret);
 
  lock_resource();

  switch ([want]) {
        case 'LIST'     { @ret = &wrapped }
        case 'SCALAR'   { $ret = &wrapped }
        else            { &wrapped }
  }
 
  unlock_resource();

  switch ([want]) {
        case 'LIST'     { return @ret }
        case 'SCALAR'   { return $ret }
        else            { return }
  }
}

Alternnatively, the return section could be just:

  return want 'LIST'   ? @ret
       : want 'SCALAR' ? $ret
       :                 undef;


   > Presumably wrapped() currently does one of 3 different 
   > things according to the value of wantarray but might be
   > enhanced to do one of up to 21 different things according 
   > to the value of want.

True, but most of those other ways are either irrelevant to this example
(i.e. make no difference to the existing behaviours) or they are sub-cases
of the existing cases (which one might or might nor choose to optimize).

Damian

Reply via email to