> All variables are rather some equivalent of package variables, where each function counts as a package that can't access variables of other function.

That's more or less how lexicals are realized in Perl.

A Pad° is a hash like structure ("namespace") like a package. (with the difference that it doesn't have globs)

Every scope has it's own pad, nesting scopes results in a chain of pads to be investigated.

You may want to play a bit with PadWalker

> Python doesn't have lexicals.

Python has closures, closures require lexicals.

> there is no equivalent to my in python.

Implementation of semantic matters not syntax or naming.

update

the first assignment in a "scope" is an implicit declaration in Python.

Sometimes it's a my sometimes an our .

The mess starts because you can't use something like strict* to catch typos and Py3 needed to introduce nonlocal to mark assignments which are not declarations.

"Explicit is better than implicit" ... LOL

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

°) Pad: = short for perlguts#Scratchpads

*) which JS successfully copied because it has var and even let now.


In reply to Re^3: Nesting Functions by LanX
in thread Nesting Functions by betmatt

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.