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

Re: Pre-RFC: Phaser Expressions

Thread Previous | Thread Next
Tom Molesworth via perl5-porters
November 16, 2021 01:10
Re: Pre-RFC: Phaser Expressions
Message ID:
On Mon, 15 Nov 2021 at 19:47, Paul "LeoNerd" Evans <>

> 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

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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About