ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl6-language
perl6-language
Re: nested subs
by Luke Palmer other posts by this author
Jun 16 2005 3:21PM messages near this date
nested subs | scalar dereferencing.
On 6/16/05, Piers Cawley <pdcawley@[...].uk>  wrote:
>  So, I was about to write the following test for Pugs:
>  
>    sub factorial (Int $n) {
>      my sub factn (Int $acc, $i) {
>        return $acc if $i > $n;
>        factn( $acc * $i, $i+1);
>      }
>      factn(1, 1);
>    }
>  
>  When I thought to check the apocalypses and exegeses and, what do you know, I
>  couldn't find any evidence that nested named functions like this were legal.
>  
>  So, are they legal?

Yep.  And they work just as if you had used an anonymous sub there--it
closes over lexicals and everything.

Luke
Thread:
Piers Cawley
Luke Palmer

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved