my $foo = sub { ... };
foo(1,2 , 3);
No, Rob's original spelling was precisely what he meant.
Rob Hoelz wrote:Not too difficult to implement on CPAN. There's enough in the
>I think lexical subroutines are a really cool feature, so I figured I'd
>try to implement them. I realize this is probably a huge undertaking,
core to support it. Basic plan: new keyword my_sub is defined via
Devel::CallParser. It performs custom parsing that turns "my_sub
foo {...}" into ops looking rather like "my $sub_foo = sub {...};"
* Rob Hoelz <r...@hoelz.ro> [2012-04-17T12:11:03]
> I think both 'my sub foo' and 'my &foo' should be accepted syntax.
"&foo" is generally used to invoke a subroutine in the olde timey fashion,
or to refer to an existing subroutine in those very limited places where the
language syntax has been special cased to notice it: defined and goto.
> Given the choice between C<<my sub f;>> and C<<my ⊂>>, I would use theHow would you define a lexical sub then?
> latter. It's shorter and (more importantly) stylistically consistent with
> existing code.
On Tue, Apr 17, 2012 at 10:52:17PM -0400, Eric Brine wrote:
> Both (B) and (C) prevent the same syntax from being used by a separate
> declaration and definition. As such, I think the best candidates are
and the definition:This could be avoided by requiring 'my sub' in both the predeclaration
Lexical scoping implies something quite different from dynamic
scoping. Are we talking about dynamic scoping or true lexical scoping?
What happens if I declare a recursive lexical sub inside of a sub of the same name, what happens?
how this will impact things like [...] method caching
I do not mean to be arguing which behaviour is right. Merely to note that
lexical variables are not in scope until the end of the statement which
declares them.
Eric Brine wrote:That's problematic, because "my sub helper { ..." looks like a lexical sub
>sub foo {
> my sub helper;
> my sub helper {
> helper();
> }
>}
declaration unto itself
As I said elsewhere in the thread, if you want to
separate declaration from definition then you need a different syntax
for the non-declaring definition
But I don't think such a facility would pull its weight.