> "But definition are different between language aren't they? Like a closure can just be an anonymous function in some languages"

Lisp popularized both concepts for decades, other languages can't bend the definitions into the opposite.

And Larry took them from Lisp after adapting it to the different syntax of Perl when designing Perl 5

A lexical variable is a variable that can be referenced only within the lexical scope of the form that establishes that variable; lexical variables have lexical scope. Each time a form creates a lexical binding of a variable, a fresh binding is established.

So there you have a form where the variables are defined at the very beginning. °

(let ((var1 init-form-1) (var2 init-form-2) ... (varm init-form-m)) form1 form2 ... formn)

Both Perl and Python avoid extra "blocks" for each declaration by coupling the declaration to the surrounding scope.

(To exactly simulate this behaviour we'd need a do block in Perl where all lexical vars are defined at the very beginning)

So yes Perl is a bit saner but with a more complex implementation than Python and JS which are pretending the declaration happened at the scopes start.

So using your arguments none of these languages are implementing lexical vars, because none is using a "let block" syntax.

My argument is that semantics matter not syntax.

AND you can easily transform Python and JS scoping to Perl's by moving the declaration at their scopes start and leaving the init parts at their respective place.

Replicating my former example

sub fun2 { my $a; print $a; # undef warning * $a = 33; }

I hope my POV is clearer now.

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

*) In order to have a fatal like in python just tie the declarations with a tied variable that croaks when fetched.

°) though I don't know the original notation in lambda calculus


In reply to Re^7: 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.