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:
Ovid
Date:
October 4, 2022 13:41
Subject:
Re: Named argument syntax (was Re: PSC #049 2022-01-07)
Message ID:
CA+M4CHsQnOeXOUartt4Hht1pMsjaK6zEoH+ev3A9bG-2JfoxAQ@mail.gmail.com
Reviving an old discussion ...

On Mon, Jan 31, 2022 at 9:50 PM Dave Mitchell <davem@iabyn.com> wrote:

> Just to be clear here. I fully expect that function calls will always
> consist of the caller passing a list to the function, and that the
> proposed named parameter syntax  is just a way of easily processing
> adjacent pairs of values in that list. So in:
>
>     sub foo(:$x, :$y) { ... }
>
> The caller is expected to pass 4 arguments. How the caller does this is up
> to the caller. They could do
>
>     foo('x', 1, 'y', '2');
>

Since arrays and hashes are flattened into a list, it seems that someone
might do sub foo(:@bar) {...} and get surprising results. Either it doesn't
do what they expect, or it's a syntax error. If named arguments can only
use scalar values, why not drop the sigil?

    sub foo (:x, :y) { ... }

Best,
Curtis "Ovid" Poe
--
CTO, All Around the World
World-class software development and consulting
https://allaroundtheworld.fr/

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