develooper Front page | perl.perl6.language | Postings from June 2005

Re: When can I take given as read?

Thread Previous | Thread Next
From:
Damian Conway
Date:
June 17, 2005 15:13
Subject:
Re: When can I take given as read?
Message ID:
42B34AEA.9060105@conway.org
Larry wrote:

> : 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?

Only that methods no longer topicalize their invocant...they now invocantize it.

Also it's not a good general solution. I can easily imagine situations where 
you want the second argument, or the last arg, to be the topic.

I still think it would be better to allow people to explicitly say what they mean:

     sub factorial (Int $n is topic) {
         return 1 when 0;
         return $n * factorial $n;
     }

Damian

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About