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

Re: Ignoring parameters

Thread Previous | Thread Next
From:
Larry Wall
Date:
June 17, 2005 12:16
Subject:
Re: Ignoring parameters
Message ID:
20050617191609.GE817@wall.org
On Thu, Jun 16, 2005 at 05:18:51PM -0400, John Siracusa wrote:
: 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.)

Something like:

    # Do something then proceed with call "as usual"
    method foo (*@args)
    {
      ./do_something_new(123, 'abc');
      ./SUPER::foo(@args);
    }

    # Pull off some args, do something, then proceed with call "as usual"
    method foo ()
    {
      ./do_something_else(val => delete %_<xyz>);
      ./SUPER::foo(%_);
    }

All methods get a slurpy %_ unless you declare your own.  But you probably
want to avoid "super" semantics and write that:

    method foo ()
    {
      ./do_something_else(val => %_<xyz>);
      next;
    }

I've also taken the liberty of deleting your delete, on the assumption
that your "next" method might want to see the same argument and do
something else with it.  A set of "next" methods need a consistent
parameter namespace in any event, so there's no harm in leaving the
parameter in %_, and some performance benefit in not doing something
better performed by GC (we hope).

Larry

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