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: When can I take given as read?
by Larry Wall other posts by this author
Jun 17 2005 11:50AM messages near this date
When can I take given as read? | Re: When can I take given as read?
On Fri, Jun 17, 2005 at 04:41:53AM +0100, Piers Cawley wrote:
: Suppose I have a simple, single argument recursive function:
: 
:   sub factorial (Int $n) {
:     return 1 if $n == 0;
:     return $n * factorial $n;
:   }
: 
: Can I write that as:
: 
:   sub factorial (Int $n:) {
:     return 1 when 0;
:     return $n * factorial $n;
:   }

As it stands right now, no.  Ordinary subs do not allow invocants.
Arguably, it'd be more consistent if ordinary subs always topicalized
their first argument.  (But blocks have to be handled differently
since they expect to see the outer binding of $_ unless the block itself
rebinds $_.)  On the other hand, it'd probably work if you threw a
"multi" in front of the "sub".

Can anyone think of a good reason not to topicalize the first arg
of ordinary subs these days?  Other than subtle encouragement toward
use of multis?  I suppose it also makes refactoring between subs and
methods more difficult in the case where you're adding an invocant,
though it actually makes it easier in the case where you're just
turning the first sub argument into an invocant because you realize
you've been writing C-style OO code...

6.5 of one, half a baker's dozen of the other...

Larry
Thread:
Piers Cawley
Larry Wall
Damian Conway
Carl Franks
Juerd
Rod Adams

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