develooper Front page | perl.perl6.language | Postings from June 2005

Re: Ignoring parameters

Thread Previous | Thread Next
From:
John Siracusa
Date:
June 16, 2005 14:19
Subject:
Re: Ignoring parameters
Message ID:
BED764FB.1FB2A%siracusa@mindspring.com
On 6/16/05, Damian Conway <damian@conway.org> wrote:
> And I think that subs and methods *should* complain about all unused
> non-optional parameters *except* invocants.

This brings up something I've been thinking about.  I sometimes write a
method in Perl 5 that does something or other and then calls the superclass
method of the same name, passing all arguments.  Or sometimes I pull off an
argument or two that only make sense to my method, leaving the rest for the
superclass method.  This is all easy when args are just items in the @_
array.

Here are some Perl 5 examples:

    # Do something then proceed with call "as usual"
    sub foo
    {
      $_[0]->do_something_new(123, 'abc');
      shift->SUPER::foo(@_);
    }

    # Pull off some args, do something, then proceed with call "as usual"
    sub foo
    {
      my($self, %args) = @_;
      $self->do_something_else(val => delete $args{'xyz'});
      $self->SUPER::foo(%args);
    }

Note that in both cases my foo() method doesn't know or care what
SUPER::foo()'s arguments are.

Now in Perl 6 I'll want to use fancy named parameters and so on, but I don't
want to lose the abilities described above.  How would those examples look
in "native" Perl 6 code?  (i.e., Without forcing all methods to have a
single slurpy *@args argument, emulating the Perl 5 mechanisms.)

-John



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About