Re: Private methods in classes and roles

2008-05-16 Thread John M. Dlugosz

Moritz Lenz moritz-at-casella.verplant.org |Perl 6| wrote:

S12 says (in the context of classes):


my method think (Brain $self: $thought)

(Such methods are completely invisible to ordinary method calls, and are
in fact called with a different syntax that uses ! in place of the .
character. See below.)

And later on, in the context of roles:

my method !foo ...
my method foo ...   # same, but &foo is aliased to &!foo

Am I right in assuming that the second example is valid only for roles?

I find this different syntax for classes and roles quite confusing. Is
it intended that way? I'd welcome a uniform syntax.

Cheers,
Moritz

  


I've asked about "my method foo" too, but had no response.  I would not 
think anything is unique to roles, rather, stuff defined in a role is 
remembered partly-digested and spilled into a class later.  You might 
want to look at what I've got thus far in my specdoc at 
.  I plan on updating that section soon, 
but you get the idea of the formalism I'm bringing to it.


--John


Re: Private methods in classes and roles

2008-05-16 Thread Moritz Lenz
and a few more thoughts:

I wrote:
> S12 says (in the context of classes):
> 
> 
> my method think (Brain $self: $thought)
> 
> (Such methods are completely invisible to ordinary method calls, and are
> in fact called with a different syntax that uses ! in place of the .
> character. See below.)

for private subs S12 also says

Generally you'd just use a lexically scoped sub, though.

my sub foo ...

[Conjectural: To put a private sub into the class, say

our sub !foo ...

]

Which lead me to the thought that 'my method foo' is a bad idea because
the lexical scoping of the 'my' is orthogonal to the scope of the class.

class A {
my method foo { }
}

class A is also {
method bar {
   # no way to access self!foo here
}
}

So is

our method !foo {}

allowed in classes? and is it the recommended way to declare private
methods?


-- 
Moritz Lenz
http://moritz.faui2k3.org/ |  http://perl-6.de/