develooper Front page | perl.perl5.porters | Postings from June 2022

Re: goto and @_

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
June 7, 2022 13:58
Subject:
Re: goto and @_
Message ID:
Yp9Ze+NDkKVOqEQq@iabyn.com
On Mon, Jun 06, 2022 at 10:04:01PM +0200, Branislav Zahradník wrote:
> local @_ = (1, @_);
> goto &orig_function;
> 
> or just:
> 
> orig_function (1, @_)


With the proposed query parameter syntax, any remaining args can be copied
(or aliased) into an array without actually being consumed. For example a
sub with a self and 3 optional coordinate arguments  might look like:

    sub display_point($self, ?@point, $x=0, $y=0, $z=0) {
        ....;
        if ($self->{parent}) {
            no warnings;
            local @_ = ($self->{parent}, @point);
            goto &display_point;
        }
    }

if called as $self->(10,20), then
    $x = 10
    $y = 20
    $z =  0
    @point = (10,20)

-- 
"There's something wrong with our bloody ships today, Chatfield."
    -- Admiral Beatty at the Battle of Jutland, 31st May 1916.

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