in reply to Re^6: Nesting Functions
in thread Nesting Functions

> "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