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

Re: Signature feature request (pre-rfc?)

Thread Previous | Thread Next
From:
Dan Book
Date:
June 6, 2022 21:16
Subject:
Re: Signature feature request (pre-rfc?)
Message ID:
CABMkAVUx7wPgjuKxRihetZMsmc03x0EVZpLs1WvXDGEJ-MzV3g@mail.gmail.com
On Mon, Jun 6, 2022 at 5:05 PM Ovid <curtis.poe@gmail.com> wrote:

> Hi all,
>
> I've just hit a weird edge case in some code I'm writing that requires a
> lot of meta programming. In this case, I have two separate modules which
> require this:
>
>     sub _internal_func ( $class, $params ) { ... }
>
> But the second class requires this:
>
>     sub _internal_func ($class) { ... }
>
> So those signatures aren't quite compatible. For the second module, my
> workaround is this:
>
>     sub _internal_func ( $class, $params = undef ) { ... }
>
> But I'm not using $params at all for the second module, meaning I need to
> declare. scalar I'm not using. I now need to document in the code why this
> has happened. I'd like to write this:
>
>     sub _internal_func ( $class, undef ) { ... }
>
> But that turns out to be a syntax error, even though it's a common idiom:
>
>     my ( $package, undef, $caller ) = caller;
>
> Since the argument list in subroutine names is effectively the same as a
> my declaration, can we unify them to have the same syntax and thus be
> less surprising?
>

I don't think we should - there are a lot of differences between "my
declaration" and "signature" syntax, and the syntax for doing this in a
signature is "$". But relevant to this, LeoNerd has previously mused over
an assignment operator that uses the signature syntax.

-Dan

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