develooper Front page | perl.perl5.porters | Postings from May 2016

Father Chrysostomos via RT
May 20, 2016 13:32

Message ID:
On Wed May 18 22:22:33 2016, sprout wrote:
> On Wed Jan 07 22:08:03 2015, aristotle wrote:
> > * Father Chrysostomos <> [2014-12-04 19:45]:
> > > $ ./perl -Ilib -e 'use feature ":all"; my sub f; BEGIN { eval "sub
> > > f{warn 42}"} f'
> > > The lexical_subs feature is experimental at -e line 1.
> > > Undefined subroutine &f called at -e line 1.
> >
> > … this *ought* to work.
> And it started working with commit v5.21.6-197-g0f94cb1, but I do not
> know why.  (That commit was not supposed to change behaviour at all.)
> It needs a test.

Much of what I said in this ticket was based on a misunderstanding of how newMYSUB determines how to install the sub.¹  Whether a newly-defined lexical sub is set aside for cloning later or cloned and installed in the lexical scope immediately is determined by whether the scope in which it is declared² is currently active (the sub at that scope level is running).

So, that

    my sub f;
    BEGIN { eval "sub f {...}" }

did not work was not due to the model followed, but simply due to a bug in the code.  I do not think it is worth poring through the code to find out exactly why it used to fail.  But it probably had something to do with the more complex structure of SV + magic not being handled correctly somewhere.  v5.21.6-197-g0f94cb1 simplified the data structure and apparently fixed the mishandling thereof at the same time.

All this is to say that this bug can be closed and that the current model, which I suggested changing, is fine.  I added a test in 38fe8a04ecd.

¹I know, I even *wrote* the code.  But by the time this ticket came up, I had forgotten it.  Also, just *look* at the code in newMYSUB.  That’s enough to hurt anyone’s head.  Maybe I should plead insanity, but not my own in sanity; rather, insanity in Perl’s run-time-vs-compile-time scoping model.

²Note the distinction between declaration and definition.  The former refers to ‘my sub’, which establishes the lexical scope.  The latter refers to the body, which defines what the sub does.


Father Chrysostomos

via perlbug:  queue: perl5 status: open Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About