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

Re: Named argument syntax (was Re: PSC #049 2022-01-07)

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
October 7, 2022 16:04
Subject:
Re: Named argument syntax (was Re: PSC #049 2022-01-07)
Message ID:
20221007170433.2675f415@shy.leonerd.org.uk
On Fri, 7 Oct 2022 10:42:23 +0100
Dave Mitchell <davem@iabyn.com> wrote:

> I'd expect :@bar to be a syntax error. But note that in a separate
> proposal, a \@ary parameter auto-dereferences and aliases a passed
> array ref, as in
> 
>         sub foo(\@numbers) { say "@numbers" }
>         foo([1,2,3]); # prints "1 2 3"
> 
> This can be combined separately with named parameters, giving
> 
>         sub foo(\:@numbers) { say "@numbers" }
>         foo("numbers => [1,2,3]); # prints "1 2 3"

My thoughts:

  sub named(:$x, :$y)     # looks nice

  sub no_slurpy(:@nums)   # should be banned

  sub dereffed(\@values)  # again looks nice

However,

  sub named_deref(:\@x)   # I think I'd prefer this spelling

To my eye, `:\@arr` looks and feels a bit better than `\:@arr` does.
Since we're banning `:@arr`, we learn to avoid a colon next to an at or
percent sign. It also fits better with what you'd pass in from the
callsite

  my $result = named_deref\@values_for_x);

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

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