Re: When can I take given as read?

2005-06-21 Thread Juerd
Carl Franks skribis 2005-06-21  8:54 (+0100):
> hmm, could we write...
> sub foo (Class $self is topic: +$foo, +$bar) {
>   .method;
> }

For such a short method, perhaps just using $_ directly makes more
sense:

sub foo (Class $_: +$foo, +$bar) {
.method;
}

> to avoid having to use ./

There are many ways to "avoid" it.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html


Re: When can I take given as read?

2005-06-21 Thread Piers Cawley
Carl Franks <[EMAIL PROTECTED]> writes:

>>  sub factorial (Int $n is topic) {
>>  return 1 when 0;
>>  return $n * factorial $n;
>>  }
>
> hmm, could we write...
>
> sub foo (Class $self is topic: +$foo, +$bar) {
>   .method;
> }
>
> to avoid having to use ./
> ?

Yay!


Re: When can I take given as read?

2005-06-21 Thread Carl Franks
>  sub factorial (Int $n is topic) {
>  return 1 when 0;
>  return $n * factorial $n;
>  }

hmm, could we write...

sub foo (Class $self is topic: +$foo, +$bar) {
  .method;
}

to avoid having to use ./
?

Cheers,
Carl


Re: When can I take given as read?

2005-06-17 Thread Damian Conway

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


Re: When can I take given as read?

2005-06-17 Thread Rod Adams

Larry Wall wrote:


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



I'm having a hard time coming up with good reasons why we don't

   s:g/ (sub|method) /{"single $1"}/;
   s:g/multi (sub|method) / $1 /;

And then have a "single" still be multi, just with a MMD distance of 
-Inf to everything.


-- Rod Adams




Re: When can I take given as read?

2005-06-17 Thread Larry Wall
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


When can I take given as read?

2005-06-16 Thread Piers Cawley
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;
  }

NB. Yes, I know it's a pathological example.