Tom asked how we'd deal with variadic subroutines without sacrificing 
compile-time information (i.e. parameter lists).

Below I've indicated how RFC 128 would handle the cases he lists.

To recap: RFC 128 proposes that parameters may be given a C<:repeat>
attribute to make them variadic within a specified range of repetitions.


   > I still almost always end up first using no protos and then employing
   > extensive run-time comparisons, such as this sequence might illustrate:
   > 
   >     confess "need args" unless @_;

sub foo( $arg: repeat{1,} ) {...}


   >     confess "need even args" unless @_ % 2 == 0;

sub foo( %args ) {...}


   >     confess "keys mustn't be refs" 
   >    if grep { ref },                   @_[map {  2*$_} 0.. int($#_/2)] }

One can't express negative conditions via parameter list.
I suppose that if user-definable attributes were available one
might be able to write:

sub foo( ( $key:notref, $value) : repeat{1,} ) {...}


   >     confess "values must be hashrefs" 
   >    if grep { reftype($_) ne 'HASH' }, @_[map {1+2*$_} 0.. int($#_/2)] }

sub foo ( ($key, \%hash) : repeat{1,} ) {...}

# or:

sub foo ( ($key, HASH $hashref) : repeat{1,} ) {...}

   
   >     confess "values must be Frobulants" 
   >    if grep { $_->isa("Frobulant")  }, @_[map {1+2*$_} 0.. int($#_/2)] }

sub foo ( (Frobulant $key, $value) : repeat{1,} ) {...}


   > Could the prototype people please report whether Tim Bunce's issues with 
   > prototypes have been intentionally/adequately addressed?

I'm not a prototype person (in fact RFC 128 makes it a hanging offence
to use that confusing word in connection with parameter lists! ;-)
Could someone please recapitulate Tim's issues?

Damian

Reply via email to