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

Re: Pre-RFC: Phaser Expressions

Thread Previous | Thread Next
From:
Tom Molesworth via perl5-porters
Date:
November 16, 2021 01:10
Subject:
Re: Pre-RFC: Phaser Expressions
Message ID:
CAGXhHdk8emwV5qNSZMHB1jnYr3Evigf_bZz7eiB52i0W7oKsVg@mail.gmail.com
On Mon, 15 Nov 2021 at 19:47, Paul "LeoNerd" Evans <leonerd@leonerd.org.uk>
wrote:

> TL;DR: Add `BEGIN expr...` syntax to hoist the evaluation time of an
>   expression into BEGIN time, without creating a new scope.
>

From the example use-cases, it seems that it's not so much the _scope_
that's an issue - what we're really looking for is a value-returning BEGIN
block?

e.g. promote BEGIN to behave like `do`, but execute the contents once the
closing brace is encountered, and provide a list of constant values:

my ($list, $of, @constants) = BEGIN { ... };

(yes, it's not as simple as that - it'd break existing usage since we'd
have to start putting semicolons after BEGIN { ... } - but details like
this would be something for an RFC stage)

The bareword expression prefix isn't too convincing, seems like it would
make it harder to review code and see exactly where the boundaries of the
BEGIN-hoisted pieces are. See `return ... or next` for example.

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