not that easy

> our vars are lexically scoped aliases to package vars.

the op-tree shows our vars as GVSV with explicit link to a STASH entry *TST::xxx

D:\tmp\pm>perl -MO=Concise,TST::foo -e"package TST; our $xxx=666; sub +foo { print $xxx}" TST::foo: 5 <1> leavesub[1 ref] K/REFC,1 ->(end) - <@> lineseq KP ->5 1 <;> nextstate(TST 3 -e:1) v ->2 4 <@> print sK ->5 2 <0> pushmark s ->3 - <1> ex-rv2sv sK/1 ->4 3 <#> gvsv[*TST::xxx] s ->4 -e syntax OK

while illguts° states

Lexicals (my and our variables) have SVs_PADMY / SVs_PADOUR

My experiments show that deleting the stash entry prior to running the code doesn't effect the correct execution. Hence I think that the refs are hardcoded (bound) into the op-tree and STASHs and PADs are primarly for lookup at compilation time. (plus ref-counting)

My experiments also showed that deleting the alias of an 'our'-var from the STASH forced a destruction of that var at the end of the scope, much like with 'my'-vars.

So I'm inclined to think that Concise is just showing an interpretation of the refadress in the optree.

Anyway all this confusion stems from fuzzy wording.

We should stop referring to private my-vars as "lexicals".

A distinction between "private" and "public" would be far better.

"lexical" should be reserved for the scope only and contrasted with "dynamic" ²

Consequence: an our-var is a "lexical and public" variable.

NB: I'm also contrasting "public" from "global", because only special vars like $_, $| or $a are really global, they always belong to main::

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

°) "Illustrated Perl-Guts" ... is it only me, or does "illguts" make you think of diarrhea?

update

²) in hindsight, lets avoid "lexical scope" and rather use the synonymous "static scope"


In reply to Re^5: PadWalker's closed_over - but for our variables? by LanX
in thread PadWalker's closed_over - but for our variables? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.