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

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

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
November 17, 2022 12:49
Subject:
Signature Defined-or assigments [was Re: Miscellaneous suggestions]
Message ID:
20221117124929.59f2c68b@shy.leonerd.org.uk
(Replying to an old thread with a new subject line - hope that's OK
 everyone.)

On Thu, 28 Nov 2019 17:06:21 +0000
Dave Mitchell <davem@iabyn.com> 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

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