> Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm > Cc: [EMAIL PROTECTED] > Date: Wed, 22 Jan 2003 09:03:13 -0600 > From: "Adam D. Lopresto" <[EMAIL PROTECTED]> > X-SMTPD: qpsmtpd/0.20, http://develooper.com/code/qpsmtpd/ > > The question is, can I create a method on a class with a different scope than > the class itself has? Put another way, it seems like > > module ArrayMath; > > sub sum(Array $this){ > $this.reduce(operator::+, 0); > } > > method Array::sum(;){ > .reduce(operator::+, 0); > } > > > (modulo syntax errors) then both should have the same visibility > (ie, module level only, unless they're somehow exported (what's that > in perl6, "is public"?)). So the question of namespace becomes > moot, because just because it's a method on Array doesn't mean it's > accessible anywhere a similar sub wouldn't be. Either could be > exported and made globally available, but I don't see why they > should have to be. Or am I missing something?
If I was designing the object system (something I have _so_ much experience with :-P ), I'd say that you can't declare methods outside of their class definition, but you can define subs that take that class in the indirect object position. sub sum(Array $this:) { $this.reduce( { $^a + $^b }, 0 ); } It's appealing just because it's so happy :). The difference between this and: class Array { # ... method sum($self:) { .reduce( { $^a + $^b }, 0 ); } # ... } Would be that the latter has access to Array's private data, while the former does not. The calling conventions would not be any different between the two. Luke