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

Re: RFC 0004 - defer {} syntax

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
June 18, 2021 16:28
Subject:
Re: RFC 0004 - defer {} syntax
Message ID:
CAHAeAG47TmWCRskiMEBpxUy_0No7tqy0-YCBGHH2WyK-UwPP-g@mail.gmail.com
On Fri, Jun 18, 2021 at 6:08 PM David Nicol <davidnicol@gmail.com> wrote:

>
>
> so what's wrong with just squidding it out in long form?
>
>    sub abcdefg {
>        my $defer;
>        ...
>        my_predicate and $defer = sub {warn "MY_PREDICATE WUZ TROO!\n"};
>        ...
>        $defer and &$defer;
>        $retval;
>    }
>

  That won't run if scope is exited during the second ellipsis.

  Whereas the defer "enqueues a block of code for later execution, when
control leaves its surrounding scope for whatever reason", so as long as
the defer statement is reached, the block will eventually run.  (Well,
untimely program termination will prevent it, I guess.)


Eirik

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