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

Re: Pre-RFC: Phaser Expressions

Thread Previous | Thread Next
Graham Knop
November 16, 2021 10:00
Re: Pre-RFC: Phaser Expressions
Message ID:
On Tue, Nov 16, 2021 at 2:10 AM Tom Molesworth via perl5-porters
<> wrote:
> On Mon, 15 Nov 2021 at 19:47, Paul "LeoNerd" Evans <> 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 { ... };

Something like this doesn't solve half of what this proposal is meant
to. While the return from the BEGIN would be calculated at compile
time, the variables would still not be populated until runtime. So
later attempts to use the variables at compile time would find the
variables uninitialized. This is what the expression prefix form is
meant to solve. Without the braces, the variables can be populated at
compile time without changing their scope.

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