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

Re: Pre-RFC: Phaser Expressions

Thread Previous | Thread Next
November 17, 2021 17:13
Re: Pre-RFC: Phaser Expressions
Message ID:
From the keyboard of Branislav Zahradník [16.11.21,11:57]:

>       >
>       > 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.
> such syntax follows KIM (referencing latest Ovid's article)
> More, such syntax may be usable also for another keywords, not only my, but also our,
> state, local

This syntax opens a can of worms and sacrifices well established perl
syntax principles for a small gain of syntactic sugar.

The RHS of an assignment is evaluated prior to assignment to the LHS.
In the compile phase, statements are examined, variables and subcalls
are allocated and woven into a syntax tree - this is my (poor) notion
of the compile time phase, where runtime may be forced via BEGIN, use.
The idea of making BEGIN blocks into part of an expression blurs the
lines between compile-time and runtime semantics for no good reason.

Quick, what happens here?

use strict;
my $oo;
$foo = do { BEGIN { 1 } };
print $foo,$/;

BEGIN, CHECK, INIT, END blocks etc. are not subroutines for a very good
reason: they are not arbitrarily callable and don't but establish some
special kind of flow control for code wrt execution time, nothing more.

If we follow that path of allowing retuns from BEGIN et al, we should -
if only for the sake of orthogonality - also allow return values for bare
blocks and other constructs of flow control, e.g. foreach loops:

     my ($foo, $ref, @bar) = foreach($thingy->sub($baz)) {
         # what gets assigned? the last values calculated?

We have map() for that and other constructs.
Please let us keep perl as simple as possible.


_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                               /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About