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

Signature Defined-or assigments [was Re: Miscellaneous suggestions]

Thread Previous | Thread Next
Paul "LeoNerd" Evans
November 17, 2022 12:49
Signature Defined-or assigments [was Re: Miscellaneous suggestions]
Message ID:
(Replying to an old thread with a new subject line - hope that's OK

On Thu, 28 Nov 2019 17:06:21 +0000
Dave Mitchell <> wrote:

> =head2 Defined-or
> in [perl #132444], Ovid suggested
>     sub f($x //= expr) { ... }
> which is like
>     sub f($x = expr) { ... }
> Except that it uses the default expression if the argument is undef as
> well as if it is missing.

I'm verymuch liking the look of this one. I'd already have a bunch of
places to use it right now if it existed.

It seems to me quite simple to implement, too. Currently OP_ARGDEFELEM
doesn't make use of its private flags, so we could add a flag to make
it have this behaviour.

> Presumably we should also have ||= .

I'm less keen on this as an idea, but it'd be so seasy to add while I'm
there looking at `//=` I *could* be talked into adding it while I'm
working in the area.

I think I would like to have a look at implementing that sometime in
the next couple of weeks (as I'd like to bring it into some related
parts of Object::Pad and the feature-class branch).

Does that suit?

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About