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

Re: RFC 0004 - defer {} syntax

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
June 20, 2021 12:09
Subject:
Re: RFC 0004 - defer {} syntax
Message ID:
20210620130922.43076d27@shy.leonerd.org.uk
On Sun, 20 Jun 2021 19:51:10 +0900
Ben Bullock <benkasminbullock@gmail.com> wrote:

> I suggested this because I can't see how running a deferred block of
> code at the end of an "if" block would be useful in practice,

The clean "mental model" of how it operates.

  "defer {} runs its code when we hit the next nested }"

As opposed to

  "defer {} runs its code when we hit the next nested } that wasn't an
  if{} or elsif{} or unless{}, or maybe we'd consider adding do {} to
  that list since you can't next out of them and what about match/case
  blocks and ...."

`defer {}` runs at the same time that `my` variables go out of scope,
and `local` modifications get undone. This is by design to make it
simpler to learn and understand.

-- 
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