develooper Front page | perl.perl5.porters | Postings from December 2021

Re: "no snails"; or having signatured subs complain about @_

Thread Previous | Thread Next
From:
Juerd Waalboer
Date:
December 3, 2021 19:59
Subject:
Re: "no snails"; or having signatured subs complain about @_
Message ID:
20211203195853.GY16385@k
Paul "LeoNerd" Evans skribis 2021-11-29 16:08 (+0000):
>The final part of the "signatures" feature still to be implemented, is
>getting rid of the @_ setup

If I understand correctly, accessing @_ is currently commonly used to determine whether an optional argument was passed:

     sub bar($self, $new = "blah") {
         $self->{bar} = $new if @_ == 2;
         $self->{bar};
     }

     ...

     $x->bar(undef);  # set bar to undef

Or maybe I'm missing something.

Now, one could hack around that with a constant that is near impossible to accidentally pass as the argument...

     use constant NONE => \do { my $x };
     sub bar($self, $new = NONE) {
         $self->{bar} = $new unless ref($new) and refaddr($new) == refaddr(NONE);
         $self->{bar};
     }

That would be ugly, but if that's what it takes to finally get signatures out of experimental status after 8 years, I'd take it. However, it seems to me that there should be a better, and officially supported, way to do this.
-- 
Met vriendelijke groet, // Kind regards, // Korajn salutojn,

Juerd Waalboer  <juerd@tnx.nl>
TNX

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